hexagon: model the PCYCLE registers
cover hexagon: model the PCYCLE registers
The pcycle registers measure activity - a very coarse and simple PMU-like feature. The baseline had a "count the instructions per TB and scale a counter" model (to be summed across vCPUs upon reg read). But that's not a good model and it adds work to all TBs.
Instead: we'll use time as a slightly better model, but only accumulating when there's activity. Using a clock is unfortunately less stable across hosts and changes to translation, but still a net improvement all things considered.
Brian Cain (2):
hw/hexagon: model PCYCLE counter target/hexagon: mark clock-backed register reads as I/O
include/hw/hexagon/hexagon_globalreg.h | 6 ++ target/hexagon/cpu.h | 2 - target/hexagon/cpu_helper.h | 6 -- target/hexagon/gen_tcg_sys.h | 12 ++- target/hexagon/helper.h | 2 + target/hexagon/translate.h | 2 - hw/hexagon/hexagon_globalreg.c | 142 ++++++++++++++++++++++++- target/hexagon/cpu.c | 10 +- target/hexagon/cpu_helper.c | 79 -------------- target/hexagon/genptr.c | 38 ++++++- target/hexagon/hexswi.c | 10 +- target/hexagon/machine.c | 2 +- target/hexagon/op_helper.c | 45 ++++++++ target/hexagon/translate.c | 21 ---- hw/hexagon/trace-events | 1 + target/hexagon/hex_common.py | 8 +- 16 files changed, 259 insertions(+), 127 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 hw/hexagon: model PCYCLE counter
{U,G,}PCYCLE now use a shared virtual-clock counter. This is closer to how the real PCYCLE behaves and avoids the extra work that was being done on every single TB.
Handle SYSCFG.PCYCLEEN and the semihosting PCYCLE read.
Remove the work-in-progress implementation that summed the TB instructions into a counter.
--- include/hw/hexagon/hexagon_globalreg.h | 6 ++ target/hexagon/cpu.h | 2 - target/hexagon/cpu_helper.h | 6 -- target/hexagon/helper.h | 2 + target/hexagon/translate.h | 2 - hw/hexagon/hexagon_globalreg.c | 142 ++++++++++++++++++++++++- target/hexagon/cpu.c | 10 +- target/hexagon/cpu_helper.c | 79 -------------- target/hexagon/genptr.c | 8 ++ target/hexagon/hexswi.c | 10 +- target/hexagon/machine.c | 2 +- target/hexagon/op_helper.c | 45 ++++++++ target/hexagon/translate.c | 21 ---- hw/hexagon/trace-events | 1 + 14 files changed, 219 insertions(+), 117 deletions(-)
include/hw/hexagon/hexagon_globalreg.h +6 -0
@@ -33,6 +33,11 @@ struct HexagonGlobalRegState {/* Global performance cycle counter base */ uint64_t g_pcycle_base; +/* Global performance cycle counter clock state */ +int64_t pcycle_start_ns; +bool pcycle_running; +uint32_t pcycle_freq_hz; +/* Properties for global register reset values */ uint32_t boot_evb;/* Boot Exception Vector Base (HEX_SREG_EVB) */ uint64_t config_table_addr;/* Configuration table base */
@@ -56,6 +61,7 @@ void hexagon_globalreg_write_masked(HexagonGlobalRegState *s, uint32_t reg, uint32_t value);/* Global performance cycle counter access */ +uint64_t hexagon_globalreg_read_pcycle (HexagonGlobalRegState *s);uint64_t hexagon_globalreg_get_pcycle_base (HexagonGlobalRegState *s);void hexagon_globalreg_set_pcycle_base (HexagonGlobalRegState *s,uint64_t value);
target/hexagon/cpu.h +0 -2
@@ -151,7 +151,6 @@ typedef struct CPUArchState {hex_lock_state_t k0_lock_state;uint32_t tlb_lock_count;uint32_t k0_lock_count; -uint64_t t_cycle_count;#endif uint32_t next_PC;uint32_t imprecise_exception;
@@ -227,7 +226,6 @@ static inline HexagonHVXContext *hex_hvx(CPUHexagonState *env) FIELD(TB_FLAGS, IS_TIGHT_LOOP, 0, 1) FIELD(TB_FLAGS, MMU_INDEX, 1, 3) -FIELD(TB_FLAGS, PCYCLE_ENABLED, 4, 1) FIELD(TB_FLAGS, HVX_COPROC_ENABLED, 5, 1) G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env,
target/hexagon/cpu_helper.h +0 -6
@@ -23,11 +23,5 @@ void hexagon_ssr_set_cause(CPUHexagonState *env, uint32_t cause);void hexagon_start_threads (CPUHexagonState *env,uint32_t mask);void hexagon_stop_thread (CPUHexagonState *env);void hexagon_resume_threads (CPUHexagonState *env,uint32_t mask); -uint64_t hexagon_get_sys_pcycle_count (CPUHexagonState *env); -uint32_t hexagon_get_sys_pcycle_count_high (CPUHexagonState *env); -uint32_t hexagon_get_sys_pcycle_count_low (CPUHexagonState *env); -void hexagon_set_sys_pcycle_count_high (CPUHexagonState *env,uint32_t val); -void hexagon_set_sys_pcycle_count_low (CPUHexagonState *env,uint32_t val); -void hexagon_set_sys_pcycle_count (CPUHexagonState *env,uint64_t val);#endif
target/hexagon/helper.h +2 -0
@@ -130,6 +130,8 @@ DEF_HELPER_2(getimask, i32, env, i32) DEF_HELPER_3(setimask, void, env, i32, i32) DEF_HELPER_2(sreg_read, i32, env, i32) DEF_HELPER_2(sreg_read_pair, i64, env, i32) +DEF_HELPER_2(upcycle_read, i32, env, i32) +DEF_HELPER_1(upcycle_read_pair, i64, env) DEF_HELPER_2(greg_read, i32, env, i32) DEF_HELPER_2(greg_read_pair, i64, env, i32)DEF_HELPER_3 (sreg_write_masked, void, env, i32, i32)
target/hexagon/translate.h +0 -2
@@ -97,10 +97,8 @@ typedef struct DisasContext {TCGv new_pred_value[NUM_PREGS ];TCGv branch_taken;TCGv dczero_addr; -bool pcycle_enabled;bool hvx_coproc_enabled;bool hvx_check_emitted; -uint32_t num_cycles; } DisasContext;bool is_gather_store_insn (DisasContext *ctx);
hw/hexagon/hexagon_globalreg.c +141 -1
202 lines not on this page · raw message
target/hexagon/cpu.c +7 -3
@@ -349,7 +349,6 @@ static TCGTBCPUState hexagon_get_tb_cpu_state(CPUState *cs) cpu =env_archcpu (env); hex_flags =FIELD_DP32 (hex_flags,TB_FLAGS ,MMU_INDEX ,cpu_mmu_index (env_cpu (env), false)); - hex_flags =FIELD_DP32 (hex_flags,TB_FLAGS ,PCYCLE_ENABLED ,1 ); hex_flags =FIELD_DP32 (hex_flags,TB_FLAGS ,HVX_COPROC_ENABLED , cpu->hvx_ctx[0 ] &&GET_SSR_FIELD (SSR_XE , env->t_sreg[HEX_SREG_SSR ]));
@@ -848,15 +847,20 @@ uint32_t hexagon_greg_read(CPUHexagonState *env, uint32_t reg) {uint32_t ssr = env->t_sreg[HEX_SREG_SSR ];int ssr_ce =GET_SSR_FIELD (SSR_CE , ssr); +HexagonCPU *cpu =env_archcpu (env);if (reg <=HEX_GREG_G3 ) {return env->greg[reg]; }switch (reg) {case HEX_GREG_GPCYCLELO : -return ssr_ce ?hexagon_get_sys_pcycle_count_low (env) :0 ; +return ssr_ce ? +hexagon_globalreg_read (cpu->globalregs,HEX_SREG_PCYCLELO , + env->threadId) :0 ;case HEX_GREG_GPCYCLEHI : -return ssr_ce ?hexagon_get_sys_pcycle_count_high (env) :0 ; +return ssr_ce ? +hexagon_globalreg_read (cpu->globalregs,HEX_SREG_PCYCLEHI , + env->threadId) :0 ;default :qemu_log_mask (LOG_UNIMP ,"reading greg %" PRId32" not yet supported.\n" , reg);
target/hexagon/cpu_helper.c +0 -79
85 lines not on this page · raw message
target/hexagon/genptr.c +8 -0
@@ -443,6 +443,12 @@ static inline void gen_read_ctrl_reg(DisasContext *ctx, const int reg_num, } else if (reg_num == HEX_REG_UTIMERHI) {gen_helper_sreg_read (dest, tcg_env,tcg_constant_i32 (HEX_SREG_TIMERHI )); + }else if (reg_num ==HEX_REG_UPCYCLELO ) { +gen_helper_upcycle_read (dest, tcg_env, +tcg_constant_i32 (HEX_SREG_PCYCLELO )); + }else if (reg_num ==HEX_REG_UPCYCLEHI ) { +gen_helper_upcycle_read (dest, tcg_env, +tcg_constant_i32 (HEX_SREG_PCYCLEHI ));#else }else if (reg_num ==HEX_REG_UTIMERLO ) {TCGv_i64 utimer =tcg_temp_new_i64 ();
@@ -488,6 +494,8 @@ static inline void gen_read_ctrl_reg_pair(DisasContext *ctx, const int reg_num,gen_helper_sreg_read (lo, tcg_env,tcg_constant_i32 (HEX_SREG_TIMERLO ));gen_helper_sreg_read (hi, tcg_env,tcg_constant_i32 (HEX_SREG_TIMERHI )); tcg_gen_concat_i32_i64(dest, lo, hi); + }else if (reg_num ==HEX_REG_UPCYCLELO ) { +gen_helper_upcycle_read_pair (dest, tcg_env);#else }else if (reg_num ==HEX_REG_UTIMERLO ) {/* One helper call, so the pair is a coherent 64-bit snapshot. */
target/hexagon/hexswi.c +8 -2
@@ -692,8 +692,14 @@ static void sim_handle_trap0(CPUHexagonState *env)case HEX_SYS_READ_PCYCLES : { - env->gpr[HEX_REG_R00 ] =hexagon_get_sys_pcycle_count_low (env); - env->gpr[HEX_REG_R01 ] =hexagon_get_sys_pcycle_count_high (env); +HexagonCPU *cpu =env_archcpu (env); +uint64_t pcycles; + +BQL_LOCK_GUARD (); + pcycles = cpu->globalregs ? +hexagon_globalreg_read_pcycle (cpu->globalregs) :0 ; + env->gpr[HEX_REG_R00 ] = (uint32_t )pcycles; + env->gpr[HEX_REG_R01 ] = (uint32_t )(pcycles >>32 );break ; }
target/hexagon/machine.c +1 -1
@@ -37,7 +37,7 @@ const VMStateDescription vmstate_hexagon_cpu = {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_UNUSED (sizeof (uint64_t )),VMSTATE_UINT32 (env.imprecise_exception, HexagonCPU),VMSTATE_END_OF_LIST ()
target/hexagon/op_helper.c +45 -0
72 lines not on this page · raw message
target/hexagon/translate.c +0 -21
@@ -64,7 +64,6 @@ TCGv hex_llsc_addr;TCGv hex_llsc_val;TCGv_i64 hex_llsc_val_i64;#ifndef CONFIG_USER_ONLY -TCGv_i64 hex_cycle_count;TCGv hex_imprecise_exception;#endif TCGv hex_vstore_addr[VSTORES_MAX ];
@@ -145,16 +144,6 @@ static void gen_precise_exception(int cause, uint32_t PC) tcg_constant_i32(PC)); } -#ifndef CONFIG_USER_ONLY -static void gen_pcycle_counters (DisasContext *ctx) -{ -if (ctx->pcycle_enabled) { -tcg_gen_addi_i64 (hex_cycle_count, hex_cycle_count, ctx->num_cycles); - } -} -#endif - -static void gen_exec_counters (DisasContext *ctx) { tcg_gen_addi_tl(hex_gpr[HEX_REG_QEMU_PKT_CNT],
@@ -163,9 +152,6 @@ static void gen_exec_counters(DisasContext *ctx) hex_gpr[HEX_REG_QEMU_INSN_CNT], ctx->num_insns);tcg_gen_addi_tl (hex_gpr[HEX_REG_QEMU_HVX_CNT ], hex_gpr[HEX_REG_QEMU_HVX_CNT ], ctx->num_hvx_insns); -#ifndef CONFIG_USER_ONLY -gen_pcycle_counters (ctx); -#endif }static bool use_goto_tb (DisasContext *ctx,target_ulong dest)
@@ -1108,8 +1094,6 @@ static void gen_commit_hvx(DisasContext *ctx) } } -#define PCYCLES_PER_PACKET 1 -static void update_exec_counters (DisasContext *ctx) {int num_real_insns =0 ;
@@ -1129,7 +1113,6 @@ static void update_exec_counters(DisasContext *ctx) ctx->num_packets++; ctx->num_insns += num_real_insns; ctx->num_hvx_insns += num_hvx_insns; - ctx->num_cycles +=PCYCLES_PER_PACKET ; }#ifndef CONFIG_USER_ONLY
@@ -1309,8 +1292,6 @@ static void hexagon_tr_init_disas_context(DisasContextBase *dcbase, ctx->hex_def =HEXAGON_CPU_GET_CLASS (hex_cpu)->hex_def; ctx->ieee_fp_extension = hex_cpu->cfg.ieee_fp_extension;#ifndef CONFIG_USER_ONLY - ctx->num_cycles =0 ; - ctx->pcycle_enabled =FIELD_EX32 (hex_flags,TB_FLAGS ,PCYCLE_ENABLED ); ctx->hvx_coproc_enabled =FIELD_EX32 (hex_flags,TB_FLAGS ,HVX_COPROC_ENABLED ); ctx->hvx_check_emitted = false;
@@ -1465,8 +1446,6 @@ void hexagon_translate_init(void) hex_cause_code =tcg_global_mem_new_i32 (tcg_env, offsetof(CPUHexagonState , cause_code),"cause_code" );#ifndef CONFIG_USER_ONLY - hex_cycle_count =tcg_global_mem_new_i64 (tcg_env, - offsetof(CPUHexagonState , t_cycle_count),"t_cycle_count" ); hex_imprecise_exception =tcg_global_mem_new (tcg_env, offsetof(CPUHexagonState , imprecise_exception),"imprecise_exception" );#endif
hw/hexagon/trace-events +1 -0
@@ -1,3 +1,4 @@ # Hexagon global register access hexagon_globalreg_read(uint32_t htid, const char *reg_name, uint32_t value) "htid=%u reg=%s value=0x%x" hexagon_globalreg_write(uint32_t htid, const char *reg_name, uint32_t value) "htid=%u reg=%s value=0x%x" +hexagon_pcycle_run_state(bool running, uint64_t base) "running=%u base=%" PRIu64
Signature · 1 line
2.34.1
Re: [PATCH 1/2] hw/hexagon: model PCYCLE counter
Quoted 9 lines · Brian Cain
{U,G,}PCYCLE now use a shared virtual-clock counter. This is closer to how the real PCYCLE behaves and avoids the extra work that was being done on every single TB.
Handle SYSCFG.PCYCLEEN and the semihosting PCYCLE read.
Remove the work-in-progress implementation that summed the TB instructions into a counter.
From what I understand, PCYCLE is different from RDTSC (x86) or CNTVCT_EL0 (aarch64) since it tracks cycles per thread, compared to globals ticks on cpu, independently of its frequency. Pushing a bit further, I also see that aarch64 has PMCCNTR_EL0, which models something similar to PCYCLE.
In the case of aarch64, it's implemented based on time also, so hexagon mimics this approach.
```
static uint64_t cycles_get_count(CPUARMState *env)
{
#ifndef CONFIG_USER_ONLY
return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
ARM_CPU_FREQ, NANOSECONDS_PER_SECOND);
#else
return cpu_get_host_ticks();
#endif
}
```So, since we are not accurate anyway, and depend on host cpu speed through time elapsed, is there any reason to have a pcycle_freq_hz property instead of a fixed number?
---
The rest looks good to me. It would be slightly easier to see the change by removing the count based wip first, and then introduce the time based implementation, but it's not a big deal.
Regards,
Pierrick
Re: [PATCH 1/2] hw/hexagon: model PCYCLE counter
Quoted 5 lines · Pierrick Bouvier
Quoted 4 lines · Brian Cain
{U,G,}PCYCLE now use a shared virtual-clock counter. This is closer to how the real PCYCLE behaves and avoids the extra work that was being done on every single TB.
Quoted 7 lines
Quoted 5 lines
Handle SYSCFG.PCYCLEEN and the semihosting PCYCLE read.
Remove the work-in-progress implementation that summed the TB instructions into a counter.
From what I understand, PCYCLE is different from RDTSC (x86) or
CNTVCT_EL0(aarch64) since it tracks cycles per thread, compared to
https://docs.qualcomm.com/doc/80-N2040-60/topic/registers.html#cycle-count-registers
PCYCLE is a global (per-core) cycle counter, not per-thread. The WIP implementation accumulated counts of packets per TB during that TB (accounting for just that thread's activity). The previous implementation on our fork summed the counters among vCPUs on PCYCLE register reads. This was "good enough" for a first generation but is a less appropriate model than provided in this series and required more work with every TB. The one nice thing was that it was stable and consistent among hosts.
Quoted 19 lines
globals ticks on cpu, independently of its frequency. Pushing a bit further, I also see that aarch64 has
PMCCNTR_EL0, which models something similar to PCYCLE.In the case of aarch64, it's implemented based on time also, so hexagon mimics this approach.
``` static uint64_t cycles_get_count(CPUARMState *env) { #ifndef CONFIG_USER_ONLY return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); #else return cpu_get_host_ticks(); #endif } ```
Quoted 5 lines
So, since we are not accurate anyway, and depend on host cpu speed through time elapsed, is there any reason to have a
pcycle_freq_hzproperty instead of a fixed number?---
That property was sort of an "apology" to any user who might long for the stability of the implementation on the fork - allowing them to calibrate as needed. I am definitely not attached to it and happy to get rid of it.
Quoted 4 lines
The rest looks good to me. It would be slightly easier to see the change by removing the count based wip first, and then introduce the time based implementation, but it's not a big deal.
Good idea - will do.
Quoted 2 lines
Regards,
Pierrick
Re: [PATCH 1/2] hw/hexagon: model PCYCLE counter
Quoted 53 lines · Brian Cain
Quoted 6 lines · Pierrick Bouvier
Quoted 5 lines · Brian Cain
{U,G,}PCYCLE now use a shared virtual-clock counter. This is closer to how
the real PCYCLE behaves and avoids the extra work that was being done on every single TB.Quoted 8 lines
Quoted 6 lines
Handle SYSCFG.PCYCLEEN and the semihosting PCYCLE read.
Remove the work-in-progress implementation that summed the TB instructions
into a counter.From what I understand, PCYCLE is different from RDTSC (x86) or
CNTVCT_EL0(aarch64) since it tracks cycles per thread, compared tohttps://docs.qualcomm.com/doc/80-N2040-60/topic/registers.html#cycle-
count-registersPCYCLE is a global (per-core) cycle counter, not per-thread. The WIP implementation accumulated counts of packets per TB during that TB (accounting for just that thread's activity). The previous implementation on our fork summed the counters among vCPUs on PCYCLE register reads. This was "good enough" for a first generation but is a less appropriate model than provided in this series and required more work with every TB. The one nice thing was that it was stable and consistent among hosts.
Quoted 23 lines
globals ticks on cpu, independently of its frequency. Pushing a bit further, I also see that aarch64 has
PMCCNTR_EL0, which models something similar to PCYCLE.In the case of aarch64, it's implemented based on time also, so hexagon mimics this approach.
``` static uint64_t cycles_get_count(CPUARMState *env) { #ifndef CONFIG_USER_ONLY return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); #else return cpu_get_host_ticks(); #endif } ```So, since we are not accurate anyway, and depend on host cpu speed through time elapsed, is there any reason to have a
pcycle_freq_hzproperty instead of a fixed number?
Quoted 7 lines
Quoted 1 line
---
That property was sort of an "apology" to any user who might long for the stability of the implementation on the fork - allowing them to calibrate as needed. I am definitely not attached to it and happy to get rid of it.
I think it would be better yes.
Quoted 11 lines
Quoted 5 lines
The rest looks good to me. It would be slightly easier to see the change by removing the count based wip first, and then introduce the time based implementation, but it's not a big deal.
Good idea - will do.
Quoted 2 lines
Regards,
Pierrick
PATCH 2/2 target/hexagon: mark clock-backed register reads as I/O
In reply to Brian CainMark scalar and pair reads of *PCYCLE* regs as I/O so icount synchronizes before reading.
Cover the read paths of {U,G}{PCYCLE,TIMER}{LO,HI,} registers.
--- target/hexagon/gen_tcg_sys.h | 12 ++++++++++-- target/hexagon/genptr.c | 30 ++++++++++++++++++++++++++---- target/hexagon/hex_common.py | 8 ++++---- 3 files changed, 40 insertions(+), 10 deletions(-)
target/hexagon/gen_tcg_sys.h +10 -2
@@ -80,18 +80,26 @@#define fGEN_TCG_Y2_wait (SHORTCODE ) \ do { \ RsV = RsV; \ + translator_io_start(&ctx->base); \ gen_helper_wait(tcg_env, tcg_constant_tl(ctx->pkt.pc)); \ } while (0)#define fGEN_TCG_Y2_resume (SHORTCODE ) \ - gen_helper_resume(tcg_env, RsV) + do { \ + translator_io_start(&ctx->base); \ + gen_helper_resume(tcg_env, RsV); \ + } while (0)#define fGEN_TCG_Y2_start (SHORTCODE ) \ - gen_helper_start(tcg_env, RsV) + do { \ + translator_io_start(&ctx->base); \ + gen_helper_start(tcg_env, RsV); \ + } while (0)#define fGEN_TCG_Y2_stop (SHORTCODE ) \ do { \ RsV = RsV; \ + translator_io_start(&ctx->base); \ gen_helper_stop(tcg_env); \ } while (0)
target/hexagon/genptr.c +26 -4
@@ -297,6 +297,9 @@ static void gen_log_sreg_write(DisasContext *ctx, int rnum, TCGv_i32 val) {uint32_t reg_mask = sreg_immut_masks[rnum]; +if (rnum ==HEX_SREG_MODECTL || rnum ==HEX_SREG_SYSCFG ) { +translator_io_start (&ctx->base); + }if (rnum ==HEX_SREG_IMASK && ctx->hex_def->hex_version <HEX_VER_V81 ) { reg_mask =0xffff0000 ;
@@ -331,8 +334,12 @@ static void gen_log_sreg_write_pair(DisasContext *ctx, int rnum, TCGv_i64 val) }G_GNUC_UNUSED -static void gen_read_sreg(TCGv_i32 dst, int reg_num) +static void gen_read_sreg(DisasContext *ctx, TCGv_i32 dst, int reg_num) { +if (reg_num ==HEX_SREG_TIMERLO || reg_num ==HEX_SREG_TIMERHI || + reg_num ==HEX_SREG_PCYCLELO || reg_num ==HEX_SREG_PCYCLEHI ) { +translator_io_start (&ctx->base); + }if (reg_num >=HEX_SREG_GLB_START || reg_num ==HEX_SREG_BADVA ) {gen_helper_sreg_read (dst, tcg_env,tcg_constant_i32 (reg_num)); }else {
@@ -341,8 +348,11 @@ static void gen_read_sreg(TCGv_i32 dst, int reg_num) }G_GNUC_UNUSED -static void gen_read_sreg_pair(TCGv_i64 dst, int reg_num) +static void gen_read_sreg_pair(DisasContext *ctx, TCGv_i64 dst, int reg_num) { +if (reg_num ==HEX_SREG_TIMERLO || reg_num ==HEX_SREG_PCYCLELO ) { +translator_io_start (&ctx->base); + }if (reg_num <HEX_SREG_GLB_START ) {if (reg_num +1 ==HEX_SREG_BADVA ) {TCGv_i32 badva =tcg_temp_new_i32 ();
@@ -359,8 +369,11 @@ static void gen_read_sreg_pair(TCGv_i64 dst, int reg_num) }G_GNUC_UNUSED -static void gen_read_greg(TCGv_i32 dst, int reg_num) +static void gen_read_greg(DisasContext *ctx, TCGv_i32 dst, int reg_num) { +if (reg_num ==HEX_GREG_GPCYCLELO || reg_num ==HEX_GREG_GPCYCLEHI ) { +translator_io_start (&ctx->base); + }if (reg_num <=HEX_GREG_G3 ) {tcg_gen_mov_i32 (dst, hex_greg[reg_num]); }else {
@@ -369,8 +382,11 @@ static void gen_read_greg(TCGv_i32 dst, int reg_num) }G_GNUC_UNUSED -static void gen_read_greg_pair(TCGv_i64 dst, int reg_num) +static void gen_read_greg_pair(DisasContext *ctx, TCGv_i64 dst, int reg_num) { +if (reg_num ==HEX_GREG_GPCYCLELO ) { +translator_io_start (&ctx->base); + }if (reg_num ==HEX_GREG_G0 || reg_num ==HEX_GREG_G2 ) {tcg_gen_concat_i32_i64 (dst, hex_greg[reg_num], hex_greg[reg_num +1 ]);
@@ -438,15 +454,19 @@ static inline void gen_read_ctrl_reg(DisasContext *ctx, const int reg_num, ctx->num_hvx_insns); #ifndef CONFIG_USER_ONLY }else if (reg_num ==HEX_REG_UTIMERLO ) { +translator_io_start (&ctx->base);gen_helper_sreg_read (dest, tcg_env,tcg_constant_i32 (HEX_SREG_TIMERLO )); }else if (reg_num ==HEX_REG_UTIMERHI ) { +translator_io_start (&ctx->base);gen_helper_sreg_read (dest, tcg_env,tcg_constant_i32 (HEX_SREG_TIMERHI )); }else if (reg_num ==HEX_REG_UPCYCLELO ) { +translator_io_start (&ctx->base);gen_helper_upcycle_read (dest, tcg_env,tcg_constant_i32 (HEX_SREG_PCYCLELO )); }else if (reg_num ==HEX_REG_UPCYCLEHI ) { +translator_io_start (&ctx->base);gen_helper_upcycle_read (dest, tcg_env,tcg_constant_i32 (HEX_SREG_PCYCLEHI ));#else
@@ -489,12 +509,14 @@ static inline void gen_read_ctrl_reg_pair(DisasContext *ctx, const int reg_num,tcg_gen_concat_i32_i64 (dest, hvx_cnt, hex_gpr[reg_num +1 ]); #ifndef CONFIG_USER_ONLY }else if (reg_num ==HEX_REG_UTIMERLO ) { +translator_io_start (&ctx->base);TCGv lo =tcg_temp_new ();TCGv hi =tcg_temp_new ();gen_helper_sreg_read (lo, tcg_env,tcg_constant_i32 (HEX_SREG_TIMERLO ));gen_helper_sreg_read (hi, tcg_env,tcg_constant_i32 (HEX_SREG_TIMERHI ));tcg_gen_concat_i32_i64 (dest, lo, hi); }else if (reg_num ==HEX_REG_UPCYCLELO ) { +translator_io_start (&ctx->base);gen_helper_upcycle_read_pair (dest, tcg_env);#else }else if (reg_num ==HEX_REG_UTIMERLO ) {
target/hexagon/hex_common.py +4 -4
@@ -1162,7 +1162,7 @@ def decl_tcg(self, f, tag, regno): self.gen_check_impl(f, regno) f.write(code_fmt(f"""\ TCGv_i32 {self.reg_tcg()} = tcg_temp_new_i32(); - gen_read_greg({self.reg_tcg()}, {self.reg_num}); + gen_read_greg(ctx, {self.reg_tcg()}, {self.reg_num}); """)) def analyze_read(self, f, regno): pass
@@ -1193,7 +1193,7 @@ def decl_tcg(self, f, tag, regno): self.gen_check_impl(f, regno) f.write(code_fmt(f"""\ TCGv_i64 {self.reg_tcg()} = tcg_temp_new_i64(); - gen_read_greg_pair({self.reg_tcg()}, {self.reg_num}); + gen_read_greg_pair(ctx, {self.reg_tcg()}, {self.reg_num}); """)) def analyze_read(self, f, regno): pass
@@ -1222,7 +1222,7 @@ def decl_tcg(self, f, tag, regno): self.decl_reg_num(f, regno) f.write(code_fmt(f"""\ TCGv_i32 {self.reg_tcg()} = tcg_temp_new_i32(); - gen_read_sreg({self.reg_tcg()}, {self.reg_num}); + gen_read_sreg(ctx, {self.reg_tcg()}, {self.reg_num}); """)) def analyze_read(self, f, regno): pass
@@ -1251,7 +1251,7 @@ def decl_tcg(self, f, tag, regno): self.decl_reg_num(f, regno) f.write(code_fmt(f"""\ TCGv_i64 {self.reg_tcg()} = tcg_temp_new_i64(); - gen_read_sreg_pair({self.reg_tcg()}, {self.reg_num}); + gen_read_sreg_pair(ctx, {self.reg_tcg()}, {self.reg_num}); """)) def analyze_read(self, f, regno): pass
Signature · 1 line
2.34.1
Re: [PATCH 2/2] target/hexagon: mark clock-backed register reads as I/O
Quoted 12 lines · Brian Cain
Mark scalar and pair reads of *PCYCLE* regs as I/O so icount synchronizes before reading.
Cover the read paths of {U,G}{PCYCLE,TIMER}{LO,HI,} registers.
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/gen_tcg_sys.h | 12 ++++++++++-- target/hexagon/genptr.c | 30 ++++++++++++++++++++++++++---- target/hexagon/hex_common.py | 8 ++++---- 3 files changed, 40 insertions(+), 10 deletions(-)
The comment on translator_io_start seems to be out of date. cpu->can_do_io will always be set transitively, and not only for icount. If I understand correctly, calling translator_io_start will simply for effect to end current TB, and start a new one.
All that to say that I'm not sure it's needed.
Did you find an issue without this?
Regards,
Pierrick
Re: [PATCH 2/2] target/hexagon: mark clock-backed register reads as I/O
Quoted 13 lines · Pierrick Bouvier
Quoted 12 lines · Brian Cain
Mark scalar and pair reads of *PCYCLE* regs as I/O so icount synchronizes before reading.
Cover the read paths of {U,G}{PCYCLE,TIMER}{LO,HI,} registers.
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/gen_tcg_sys.h | 12 ++++++++++-- target/hexagon/genptr.c | 30 ++++++++++++++++++++++++++---- target/hexagon/hex_common.py | 8 ++++---- 3 files changed, 40 insertions(+), 10 deletions(-)
Quoted 7 lines
The comment on
translator_io_startseems to be out of date.cpu->can_do_iowill always be set transitively, and not only for icount. If I understand correctly, callingtranslator_io_startwill simply for effect to end current TB, and start a new one.All that to say that I'm not sure it's needed.
Did you find an issue without this?
IIRC without this change we get a "Bad icount read" when performing the I/O side effects of instructions like reading from the cycle/timer registers.
Quoted 3 lines
Regards,
Pierrick
Re: [PATCH 2/2] target/hexagon: mark clock-backed register reads as I/O
Quoted 21 lines · Brian Cain
Quoted 19 lines · Pierrick Bouvier
Quoted 4 lines · Brian Cain
Mark scalar and pair reads of *PCYCLE* regs as I/O so icount synchronizes
before reading.Quoted 9 lines
Cover the read paths of {U,G}{PCYCLE,TIMER}{LO,HI,} registers.
Signed-off-by Brian Cain <[email protected]>---
target/hexagon/gen_tcg_sys.h| 12 ++++++++++-- target/hexagon/genptr.c | 30 ++++++++++++++++++++++++++----target/hexagon/hex_common.py| 8 ++++----3 files changed, 40 insertions(+), 10 deletions(-)The comment on
translator_io_startseems to be out of date.cpu->can_do_iowill always be set transitively, and not only for icount. If I understand correctly, callingtranslator_io_startwill simply for effect to end current TB, and start a new one.
Quoted 7 lines
Quoted 2 lines
All that to say that I'm not sure it's needed.
Did you find an issue without this?IIRC without this change we get a "Bad icount read" when performing the I/O side effects of instructions like reading from the cycle/timer registers.
Fair enough.
Indeed, other arch use the same mechanism for such kind of registers. I'm not sure about all the details, but makes sense to do the same.
Regards,
Pierrick
Re: [PATCH 2/2] target/hexagon: mark clock-backed register reads as I/O
Quoted 23 lines · Pierrick Bouvier
Quoted 22 lines · Brian Cain
Quoted 21 lines · Pierrick Bouvier
Quoted 4 lines · Brian Cain
Mark scalar and pair reads of *PCYCLE* regs as I/O so icount synchronizes
before reading.Quoted 9 lines
Cover the read paths of {U,G}{PCYCLE,TIMER}{LO,HI,} registers.
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/gen_tcg_sys.h | 12 ++++++++++-- target/hexagon/genptr.c | 30 ++++++++++++++++++++++++++---- target/hexagon/hex_common.py | 8 ++++---- 3 files changed, 40 insertions(+), 10 deletions(-)The comment on
translator_io_startseems to be out of date.cpu->can_do_iowill always be set transitively, and not only for icount. If I understand correctly, callingtranslator_io_startwill simply for effect to end current TB, and start a new one.All that to say that I'm not sure it's needed.
Did you find an issue without this?
Quoted 7 lines
Quoted 4 lines
IIRC without this change we get a "Bad icount read" when performing the I/O side effects of instructions like reading from the cycle/timer registers.
Fair enough.
Indeed, other arch use the same mechanism for such kind of registers. I'm not sure about all the details, but makes sense to do the same.
Oh - err, oops - but after looking closer, I did incorrectly apply some of these to instructions that don't trigger I/O. I'll remove changes from those (start/stop/wait/resume) in v2.
Re: [PATCH 2/2] target/hexagon: mark clock-backed register reads as I/O
In reply to Brian CainQuoted 12 lines · Brian Cain
Mark scalar and pair reads of *PCYCLE* regs as I/O so icount synchronizes before reading.
Cover the read paths of {U,G}{PCYCLE,TIMER}{LO,HI,} registers.
Signed-off-by Brian Cain <[email protected]>--- target/hexagon/gen_tcg_sys.h | 12 ++++++++++-- target/hexagon/genptr.c | 30 ++++++++++++++++++++++++++---- target/hexagon/hex_common.py | 8 ++++---- 3 files changed, 40 insertions(+), 10 deletions(-)