Do away with TB retranslation
v4 cover Do away with TB retranslation
Version 4:
* Typos noticed by pmm during round 3.
* RB's collected during round 3.
* Reduce the number of TBs allocated.
I believe the only patch left without an RB is 24; and of course 26 which is new.
r~
Richard Henderson (26):
tcg: Rename debug_insn_start to insn_start
target-*: Unconditionally emit tcg_gen_insn_start target-*: Increment num_insns immediately after tcg_gen_insn_start target-*: Introduce and use cpu_breakpoint_test
tcg: Allow extra data to be attached to insn_start
target-arm: Add condexec state to insn_start
target-i386: Add cc_op state to insn_start
target-mips: Add delayed branch state to insn_start
target-s390x: Add cc_op state to insn_start
target-sh4: Add flags state to insn_start
target-cris: Mirror gen_opc_pc into insn_start
target-sparc: Tidy gen_branch_a interface
target-sparc: Split out gen_branch_n
target-sparc: Remove gen_opc_jump_pc
target-sparc: Add npc state to insn_start
tcg: Merge cpu_gen_code into tb_gen_code
target-*: Drop cpu_gen_code define
tcg: Add TCG_MAX_INSNS
tcg: Pass data argument to restore_state_to_opc
tcg: Save insn data and use it in cpu_restore_state_from_tb
tcg: Remove gen_intermediate_code_pc
tcg: Remove tcg_gen_code_search_pc
tcg: Emit prologue to the beginning of code_gen_buffer
tcg: Allocate a guard page after code_gen_buffer
tcg: Check for overflow via highwater mark
tcg: Adjust CODE_GEN_AVG_BLOCK_SIZE
include/exec/exec-all.h | 23 +- include/qom/cpu.h | 16 ++ target-alpha/cpu.h | 1 - target-alpha/translate.c | 70 ++---- target-arm/cpu.h | 2 +- target-arm/translate-a64.c | 48 +--- target-arm/translate.c | 83 +++---- target-arm/translate.h | 8 +- target-cris/cpu.h | 1 - target-cris/translate.c | 93 ++------ target-cris/translate_v10.c | 3 - target-i386/cpu.h | 2 +- target-i386/translate.c | 106 +++------ target-lm32/cpu.h | 1 - target-lm32/translate.c | 83 ++----- target-m68k/cpu.h | 1 - target-m68k/translate.c | 82 ++----- target-microblaze/cpu.h | 1 - target-microblaze/translate.c | 83 ++----- target-mips/cpu.h | 2 +- target-mips/translate.c | 98 +++----- target-moxie/cpu.h | 1 - target-moxie/translate.c | 82 +++---- target-openrisc/cpu.h | 1 - target-openrisc/translate.c | 78 ++----- target-ppc/cpu.h | 1 - target-ppc/translate.c | 72 ++---- target-s390x/cpu.h | 2 +- target-s390x/translate.c | 78 ++----- target-sh4/cpu.h | 2 +- target-sh4/translate.c | 91 +++----- target-sparc/cpu.h | 2 +- target-sparc/translate.c | 185 +++++++-------- target-tilegx/cpu.h | 1 - target-tilegx/translate.c | 58 ++--- target-tricore/translate.c | 59 ++--- target-unicore32/translate.c | 83 ++----- target-xtensa/cpu.h | 1 - target-xtensa/translate.c | 79 ++----- tcg/tcg-op.h | 52 ++++- tcg/tcg-opc.h | 4 +- tcg/tcg.c | 168 ++++++++------ tcg/tcg.h | 20 +- tci.c | 9 - translate-all.c | 520 +++++++++++++++++++++++++----------------- 45 files changed, 964 insertions(+), 1492 deletions(-)
Signature · 1 line
2.4.3
PATCH v4 2/26 target-*: Unconditionally emit tcg_gen_insn_start
While we're at it, emit the opcode adjacent to where we currently record data for search_pc. This puts gen_io_start et al on the "correct" side of the marker.
--- target-alpha/translate.c | 6 ++---- target-arm/translate-a64.c | 5 +---- target-arm/translate.c | 5 +---- target-cris/translate.c | 5 +---- target-cris/translate_v10.c | 3 --- target-i386/translate.c | 5 ++--- target-lm32/translate.c | 5 +---- target-m68k/translate.c | 10 +++++----- target-microblaze/translate.c | 5 +---- target-mips/translate.c | 9 ++++----- target-moxie/translate.c | 6 ++---- target-openrisc/translate.c | 5 +---- target-ppc/translate.c | 5 ++--- target-s390x/translate.c | 6 ++---- target-sh4/translate.c | 14 +++++--------- target-sparc/translate.c | 10 +++++----- target-tilegx/translate.c | 6 ++---- target-tricore/translate.c | 2 ++ target-unicore32/translate.c | 5 +---- target-xtensa/translate.c | 5 +---- 20 files changed, 41 insertions(+), 81 deletions(-)
target-alpha/translate.c +2 -4
@@ -2933,16 +2933,14 @@ static inline void gen_intermediate_code_internal(AlphaCPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } +tcg_gen_insn_start (ctx.pc); +if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); } insn =cpu_ldl_code (env, ctx.pc); num_insns++; -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (ctx.pc); - } -TCGV_UNUSED_I64 (ctx.zero);TCGV_UNUSED_I64 (ctx.sink);TCGV_UNUSED_I64 (ctx.lit);
target-arm/translate-a64.c +1 -4
@@ -11103,15 +11103,12 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } +tcg_gen_insn_start (dc->pc);if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); } -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (dc->pc); - } -if (dc->ss_active && !dc->pstate_ss) {/* Singlestep state is Active-pending. * If we're in this state at the start of a TB then either
target-arm/translate.c +1 -4
@@ -11348,14 +11348,11 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } +tcg_gen_insn_start (dc->pc);if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO ))gen_io_start (); -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (dc->pc); - } -if (dc->ss_active && !dc->pstate_ss) {/* Singlestep state is Active-pending. * If we're in this state at the start of a TB then either
target-cris/translate.c +1 -4
@@ -2994,10 +2994,6 @@ static unsigned int crisv32_decoder(CPUCRISState *env, DisasContext *dc)int insn_len =2 ;int i; -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (dc->pc); - } -/* Load a halfword onto the instruction register. */ dc->ir =cris_fetch (env, dc, dc->pc,2 ,0 );
@@ -3197,6 +3193,7 @@ gen_intermediate_code_internal(CRISCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } +tcg_gen_insn_start (dc->pc);/* Pretty disas. */ LOG_DIS ("%8.8x:\t" , dc->pc);
target-cris/translate_v10.c +0 -3
@@ -1199,9 +1199,6 @@ static unsigned int crisv10_decoder(CPUCRISState *env, DisasContext *dc) {unsigned int insn_len =2 ; -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP ))) -tcg_gen_insn_start (dc->pc); -/* Load a halfword onto the instruction register. */ dc->ir =cpu_lduw_code (env, dc->pc);
target-i386/translate.c +2 -3
@@ -4401,9 +4401,6 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,target_ulong next_eip, tval;int rex_w, rex_r; -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (pc_start); - } s->pc = pc_start; prefixes =0 ; s->override =-1 ;
@@ -7962,6 +7959,8 @@ static inline void gen_intermediate_code_internal(X86CPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } +tcg_gen_insn_start (pc_ptr); +if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO ))gen_io_start ();
target-lm32/translate.c +1 -4
@@ -1005,10 +1005,6 @@ static const DecoderInfo decinfo[] = {static inline void decode (DisasContext *dc,uint32_t ir) { -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (dc->pc); - } - dc->ir = ir;LOG_DIS ("%8.8x\t" , dc->ir);
@@ -1106,6 +1102,7 @@ void gen_intermediate_code_internal(LM32CPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } +tcg_gen_insn_start (dc->pc);/* Pretty disas. */ LOG_DIS ("%8.8x:\t" , dc->pc);
target-m68k/translate.c +5 -5
@@ -2955,10 +2955,6 @@ static void disas_m68k_insn(CPUM68KState * env, DisasContext *s) {uint16_t insn; -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (s->pc); - } - insn =cpu_lduw_code (env, s->pc); s->pc +=2 ;
@@ -3025,8 +3021,12 @@ gen_intermediate_code_internal(M68kCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) +tcg_gen_insn_start (dc->pc); + +if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); + } + dc->insn_pc = dc->pc;disas_m68k_insn (env, dc); num_insns++;
target-microblaze/translate.c +1 -4
@@ -1588,10 +1588,6 @@ static inline void decode(DisasContext *dc, uint32_t ir) {int i; -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (dc->pc); - } - dc->ir = ir;LOG_DIS ("%8.8x\t" , dc->ir);
@@ -1718,6 +1714,7 @@ gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } +tcg_gen_insn_start (dc->pc);/* Pretty disas. */ LOG_DIS ("%8.8x:\t" , dc->pc);
target-mips/translate.c +4 -5
@@ -18904,10 +18904,6 @@ static void decode_opc(CPUMIPSState *env, DisasContext *ctx)gen_set_label (l1); } -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (ctx->pc); - } - op =MASK_OP_MAJOR (ctx->opcode); rs = (ctx->opcode >>21 ) &0x1f ; rt = (ctx->opcode >>16 ) &0x1f ;
@@ -19622,8 +19618,11 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) +tcg_gen_insn_start (ctx.pc); + +if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); + } is_slot = ctx.hflags &MIPS_HFLAG_BMASK ;if (!(ctx.hflags &MIPS_HFLAG_M16 )) {
target-moxie/translate.c +2 -4
@@ -153,10 +153,6 @@ static int decode_opc(MoxieCPU *cpu, DisasContext *ctx)/* Set the default instruction length. */ int length =2 ; -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (ctx->pc); - } -/* Examine the 16-bit opcode. */ opcode = ctx->opcode;
@@ -865,6 +861,8 @@ gen_intermediate_code_internal(MoxieCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } +tcg_gen_insn_start (ctx.pc); + ctx.opcode =cpu_lduw_code (env, ctx.pc); ctx.pc +=decode_opc (cpu, &ctx); num_insns++;
target-openrisc/translate.c +1 -4
@@ -1687,10 +1687,7 @@ static inline void gen_intermediate_code_internal(OpenRISCCPU *cpu, tcg_ctx.gen_opc_instr_start[k] =1 ; tcg_ctx.gen_opc_icount[k] = num_insns; } - -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (dc->pc); - } +tcg_gen_insn_start (dc->pc);if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start ();
target-ppc/translate.c +2 -3
@@ -11502,6 +11502,8 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } +tcg_gen_insn_start (ctx.nip); +LOG_DISAS ("----------------\n" );LOG_DISAS ("nip=" TARGET_FMT_lx" super=%d ir=%d\n" , ctx.nip, ctx.mem_idx, (int )msr_ir);
@@ -11515,9 +11517,6 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,LOG_DISAS ("translate opcode %08x (%02x %02x %02x) (%s)\n" , ctx.opcode,opc1 (ctx.opcode),opc2 (ctx.opcode),opc3 (ctx.opcode), ctx.le_mode ?"little" :"big" ); -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (ctx.nip); - } ctx.nip +=4 ; table = env->opcodes; num_insns++;
target-s390x/translate.c +2 -4
@@ -5370,14 +5370,12 @@ static inline void gen_intermediate_code_internal(S390CPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } +tcg_gen_insn_start (dc.pc); +if (++num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); } -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (dc.pc); - } - status =NO_EXIT ;if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) { QTAILQ_FOREACH(bp, &cs->breakpoints, entry) {
target-sh4/translate.c +5 -9
@@ -1790,10 +1790,6 @@ static void decode_opc(DisasContext * ctx) {uint32_t old_flags = ctx->flags; -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (ctx->pc); - } -_decode_opc (ctx);if (old_flags & (DELAY_SLOT |DELAY_SLOT_CONDITIONAL )) {
@@ -1876,12 +1872,12 @@ gen_intermediate_code_internal(SuperHCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_instr_start[ii] =1 ; tcg_ctx.gen_opc_icount[ii] = num_insns; } -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) +tcg_gen_insn_start (ctx.pc); + +if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); -#if 0 -fprintf (stderr,"Loading opcode at address 0x%08x\n" , ctx.pc); -fflush (stderr); -#endif + } + ctx.opcode =cpu_lduw_code (env, ctx.pc);decode_opc (&ctx); num_insns++;
target-sparc/translate.c +5 -5
@@ -2482,10 +2482,6 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn)TCGv_i64 cpu_src1_64, cpu_src2_64, cpu_dst_64;target_long simm; -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (dc->pc); - } - opc =GET_FIELD (insn,0 ,1 ); rd =GET_FIELD (insn,2 ,6 );
@@ -5271,8 +5267,12 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu, tcg_ctx.gen_opc_icount[lj] = num_insns; } } -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) +tcg_gen_insn_start (dc->pc); + +if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); + } + last_pc = dc->pc; insn =cpu_ldl_code (env, dc->pc);
target-tilegx/translate.c +2 -4
@@ -2008,10 +2008,6 @@ static void translate_one_bundle(DisasContext *dc, uint64_t bundle) } dc->num_wb =0 ; -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (dc->pc); - } -qemu_log_mask (CPU_LOG_TB_IN_ASM ," %" PRIx64": { " , dc->pc);if (get_Mode (bundle)) {notice_excp (dc, bundle,"y0" ,decode_y0 (dc, bundle));
@@ -2100,6 +2096,8 @@ static inline void gen_intermediate_code_internal(TileGXCPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } +tcg_gen_insn_start (dc->pc); +translate_one_bundle (dc,cpu_ldq_data (env, dc->pc));if (dc->exit_tb) {
target-tricore/translate.c +2 -0
@@ -8292,6 +8292,8 @@ gen_intermediate_code_internal(TriCoreCPU *cpu, struct TranslationBlock *tb,tcg_clear_temp_count ();gen_tb_start (tb);while (ctx.bstate ==BS_NONE ) { +tcg_gen_insn_start (ctx.pc); + ctx.opcode =cpu_ldl_code (env, ctx.pc);decode_opc (env, &ctx,0 );
target-unicore32/translate.c +1 -4
@@ -1794,10 +1794,6 @@ static void disas_uc32_insn(CPUUniCore32State *env, DisasContext *s)UniCore32CPU *cpu =uc32_env_get_cpu (env);unsigned int insn; -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (s->pc); - } - insn =cpu_ldl_code (env, s->pc); s->pc +=4 ;
@@ -1941,6 +1937,7 @@ static inline void gen_intermediate_code_internal(UniCore32CPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } +tcg_gen_insn_start (dc->pc);if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start ();
target-xtensa/translate.c +1 -4
@@ -3076,10 +3076,7 @@ void gen_intermediate_code_internal(XtensaCPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = insn_count; } - -if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_insn_start (dc.pc); - } +tcg_gen_insn_start (dc.pc); ++dc.ccount_delta;
Signature · 1 line
2.4.3
PATCH v4 3/26 target-*: Increment num_insns immediately after tcg_gen_insn_start
In reply to Richard HendersonThis does tidy the icount test common to all targets.
--- target-alpha/translate.c | 4 ++-- target-arm/translate-a64.c | 6 +++--- target-arm/translate.c | 7 ++++--- target-cris/translate.c | 4 ++-- target-i386/translate.c | 5 +++-- target-lm32/translate.c | 5 ++--- target-m68k/translate.c | 4 ++-- target-microblaze/translate.c | 5 +++-- target-mips/translate.c | 5 ++--- target-moxie/translate.c | 2 +- target-openrisc/translate.c | 4 ++-- target-ppc/translate.c | 4 ++-- target-s390x/translate.c | 3 ++- target-sh4/translate.c | 4 ++-- target-sparc/translate.c | 4 ++-- target-tilegx/translate.c | 3 ++- target-tricore/translate.c | 3 +-- target-unicore32/translate.c | 4 ++-- target-xtensa/translate.c | 4 ++-- 19 files changed, 41 insertions(+), 39 deletions(-)
target-alpha/translate.c +2 -2
@@ -2934,12 +2934,12 @@ static inline void gen_intermediate_code_internal(AlphaCPU *cpu, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (ctx.pc); + num_insns++; -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); } insn =cpu_ldl_code (env, ctx.pc); - num_insns++;TCGV_UNUSED_I64 (ctx.zero);TCGV_UNUSED_I64 (ctx.sink);
target-arm/translate-a64.c +3 -3
@@ -11104,8 +11104,9 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (dc->pc); + num_insns++; -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
@@ -11120,7 +11121,7 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,* "did not step an insn" case, and so the syndrome ISV and EX * bits should be zero. */ -assert (num_insns ==0 ); +assert (num_insns ==1 );gen_exception (EXCP_UDEF ,syn_swstep (dc->ss_same_el,0 ,0 ),default_exception_el (dc)); dc->is_jmp =DISAS_EXC ;
@@ -11139,7 +11140,6 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,* Also stop translation when a page boundary is reached. This * ensures prefetch aborts occur at the right place. */ - num_insns++; } while (!dc->is_jmp && !tcg_op_buf_full() && !cs->singlestep_enabled && !singlestep &&
target-arm/translate.c +4 -3
@@ -11349,9 +11349,11 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (dc->pc); + num_insns++; -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); + }if (dc->ss_active && !dc->pstate_ss) {/* Singlestep state is Active-pending.
@@ -11364,7 +11366,7 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,* "did not step an insn" case, and so the syndrome ISV and EX * bits should be zero. */ -assert (num_insns ==0 ); +assert (num_insns ==1 );gen_exception (EXCP_UDEF ,syn_swstep (dc->ss_same_el,0 ,0 ),default_exception_el (dc)); goto done_generating;
@@ -11400,7 +11402,6 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,* Otherwise the subsequent code could get translated several times. * Also stop translation when a page boundary is reached. This * ensures prefetch aborts occur at the right place. */ - num_insns ++; } while (!dc->is_jmp && !tcg_op_buf_full() && !cs->singlestep_enabled && !singlestep &&
target-cris/translate.c +2 -2
@@ -3194,11 +3194,12 @@ gen_intermediate_code_internal(CRISCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (dc->pc); + num_insns++;/* Pretty disas. */ LOG_DIS ("%8.8x:\t" , dc->pc); -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); } dc->clear_x =1 ;
@@ -3210,7 +3211,6 @@ gen_intermediate_code_internal(CRISCPU *cpu, TranslationBlock *tb,cris_clear_x_flag (dc); } - num_insns++;/* Check for delayed branches here. If we do it before actually generating any host code, the simulator will just loop doing nothing for on this program location. */
target-i386/translate.c +3 -2
@@ -7960,12 +7960,13 @@ static inline void gen_intermediate_code_internal(X86CPU *cpu, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (pc_ptr); + num_insns++; -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); + } pc_ptr =disas_insn (env, dc, pc_ptr); - num_insns++;/* stop translation if indicated */ if (dc->is_jmp)break ;
target-lm32/translate.c +2 -3
@@ -1103,18 +1103,17 @@ void gen_intermediate_code_internal(LM32CPU *cpu, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (dc->pc); + num_insns++;/* Pretty disas. */ LOG_DIS ("%8.8x:\t" , dc->pc); -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }decode (dc,cpu_ldl_code (env, dc->pc)); dc->pc +=4 ; - num_insns++; - }while (!dc->is_jmp && !tcg_op_buf_full () && !cs->singlestep_enabled
target-m68k/translate.c +2 -2
@@ -3022,14 +3022,14 @@ gen_intermediate_code_internal(M68kCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (dc->pc); + num_insns++; -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); } dc->insn_pc = dc->pc;disas_m68k_insn (env, dc); - num_insns++; } while (!dc->is_jmp && !tcg_op_buf_full() && !cs->singlestep_enabled && !singlestep &&
target-microblaze/translate.c +3 -2
@@ -1715,19 +1715,20 @@ gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (dc->pc); + num_insns++;/* Pretty disas. */ LOG_DIS ("%8.8x:\t" , dc->pc); -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); + } dc->clear_imm =1 ;decode (dc,cpu_ldl_code (env, dc->pc));if (dc->clear_imm) dc->tb_flags &= ~IMM_FLAG ; dc->pc +=4 ; - num_insns++;if (dc->delayed_branch) { dc->delayed_branch--;
target-mips/translate.c +2 -3
@@ -19619,8 +19619,9 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (ctx.pc); + num_insns++; -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
@@ -19659,8 +19660,6 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb, } ctx.pc += insn_bytes; - num_insns++; -/* Execute a branch and its delay slot as a single instruction. This is what GDB expects and is consistent with what the hardware does (e.g. if a delay slot instruction faults, the
target-moxie/translate.c +1 -1
@@ -862,10 +862,10 @@ gen_intermediate_code_internal(MoxieCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (ctx.pc); + num_insns++; ctx.opcode =cpu_lduw_code (env, ctx.pc); ctx.pc +=decode_opc (cpu, &ctx); - num_insns++;if (cs->singlestep_enabled) {break ;
target-openrisc/translate.c +2 -2
@@ -1688,8 +1688,9 @@ static inline void gen_intermediate_code_internal(OpenRISCCPU *cpu, tcg_ctx.gen_opc_icount[k] = num_insns; }tcg_gen_insn_start (dc->pc); + num_insns++; -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); } dc->ppc = dc->pc -4 ;
@@ -1698,7 +1699,6 @@ static inline void gen_intermediate_code_internal(OpenRISCCPU *cpu,tcg_gen_movi_tl (cpu_npc, dc->npc);disas_openrisc_insn (dc, cpu); dc->pc = dc->npc; - num_insns++;/* delay slot */ if (dc->delayed_branch) { dc->delayed_branch--;
target-ppc/translate.c +2 -2
@@ -11503,11 +11503,12 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (ctx.nip); + num_insns++;LOG_DISAS ("----------------\n" );LOG_DISAS ("nip=" TARGET_FMT_lx" super=%d ir=%d\n" , ctx.nip, ctx.mem_idx, (int )msr_ir); -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO ))gen_io_start ();if (unlikely (need_byteswap (&ctx))) { ctx.opcode =bswap32 (cpu_ldl_code (env, ctx.nip));
@@ -11519,7 +11520,6 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu, opc3(ctx.opcode), ctx.le_mode ? "little" : "big"); ctx.nip +=4 ; table = env->opcodes; - num_insns++; handler = table[opc1 (ctx.opcode)];if (is_indirect_opcode (handler)) { table =ind_table (handler);
target-s390x/translate.c +2 -1
@@ -5371,8 +5371,9 @@ static inline void gen_intermediate_code_internal(S390CPU *cpu, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (dc.pc); + num_insns++; -if (++num_insns == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
target-sh4/translate.c +2 -2
@@ -1873,14 +1873,14 @@ gen_intermediate_code_internal(SuperHCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_icount[ii] = num_insns; }tcg_gen_insn_start (ctx.pc); + num_insns++; -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); } ctx.opcode =cpu_lduw_code (env, ctx.pc);decode_opc (&ctx); - num_insns++; ctx.pc +=2 ;if ((ctx.pc & (TARGET_PAGE_SIZE -1 )) ==0 )break ;
target-sparc/translate.c +2 -2
@@ -5268,8 +5268,9 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu, } }tcg_gen_insn_start (dc->pc); + num_insns++; -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
@@ -5277,7 +5278,6 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu, insn =cpu_ldl_code (env, dc->pc);disas_sparc_insn (dc, insn); - num_insns++;if (dc->is_br)break ;
target-tilegx/translate.c +2 -1
@@ -2097,6 +2097,7 @@ static inline void gen_intermediate_code_internal(TileGXCPU *cpu, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (dc->pc); + num_insns++;translate_one_bundle (dc,cpu_ldq_data (env, dc->pc));
@@ -2105,7 +2106,7 @@ static inline void gen_intermediate_code_internal(TileGXCPU *cpu,break ; } dc->pc +=TILEGX_BUNDLE_SIZE_IN_BYTES ; -if (++num_insns >= max_insns +if (num_insns >= max_insns || dc->pc >= next_page_start ||tcg_op_buf_full ()) {/* Ending the TB due to TB size or page boundary. Set PC. */
target-tricore/translate.c +1 -2
@@ -8293,12 +8293,11 @@ gen_intermediate_code_internal(TriCoreCPU *cpu, struct TranslationBlock *tb,gen_tb_start (tb);while (ctx.bstate ==BS_NONE ) {tcg_gen_insn_start (ctx.pc); + num_insns++; ctx.opcode =cpu_ldl_code (env, ctx.pc);decode_opc (env, &ctx,0 ); - num_insns++; -if (tcg_op_buf_full ()) {gen_save_pc (ctx.next_pc);tcg_gen_exit_tb (0 );
target-unicore32/translate.c +2 -2
@@ -1938,8 +1938,9 @@ static inline void gen_intermediate_code_internal(UniCore32CPU *cpu, tcg_ctx.gen_opc_icount[lj] = num_insns; }tcg_gen_insn_start (dc->pc); + num_insns++; -if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) { +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
@@ -1958,7 +1959,6 @@ static inline void gen_intermediate_code_internal(UniCore32CPU *cpu,* Otherwise the subsequent code could get translated several times. * Also stop translation when a page boundary is reached. This * ensures prefetch aborts occur at the right place. */ - num_insns++; } while (!dc->is_jmp && !tcg_op_buf_full() && !cs->singlestep_enabled && !singlestep &&
target-xtensa/translate.c +2 -2
@@ -3077,10 +3077,11 @@ void gen_intermediate_code_internal(XtensaCPU *cpu, tcg_ctx.gen_opc_icount[lj] = insn_count; }tcg_gen_insn_start (dc.pc); + ++insn_count; ++dc.ccount_delta; -if (insn_count +1 == max_insns && (tb->cflags &CF_LAST_IO )) { +if (insn_count == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
@@ -3101,7 +3102,6 @@ void gen_intermediate_code_internal(XtensaCPU *cpu, }disas_xtensa_insn (env, &dc); - ++insn_count;if (dc.icount) {tcg_gen_mov_i32 (cpu_SR[ICOUNT ], dc.next_icount); }
Signature · 1 line
2.4.3
PATCH v4 4/26 target-*: Introduce and use cpu_breakpoint_test
In reply to Richard HendersonReduce the boilerplate required for each target. At the same time, move the test for breakpoint after calling tcg_gen_insn_start.
Note that arm and aarch64 do not use cpu_breakpoint_test, but still move the inline test down after tcg_gen_insn_start.
--- include/qom/cpu.h | 16 ++++++++++++++++ target-alpha/translate.c | 13 ++++--------- target-arm/translate-a64.c | 26 +++++++++++++------------- target-arm/translate.c | 31 ++++++++++++++++--------------- target-cris/translate.c | 27 ++++++++------------------- target-i386/translate.c | 17 +++++++---------- target-lm32/translate.c | 25 +++++++------------------ target-m68k/translate.c | 18 ++++++------------ target-microblaze/translate.c | 36 +++++++++++++----------------------- target-mips/translate.c | 25 ++++++++++--------------- target-moxie/translate.c | 19 +++++++------------ target-openrisc/translate.c | 24 +++++++----------------- target-ppc/translate.c | 14 +++++--------- target-s390x/translate.c | 16 ++++++---------- target-sh4/translate.c | 20 ++++++++------------ target-sparc/translate.c | 23 ++++++++++------------- target-unicore32/translate.c | 24 ++++++++++-------------- target-xtensa/translate.c | 25 +++++++------------------ 18 files changed, 160 insertions(+), 239 deletions(-)
include/qom/cpu.h +16 -0
@@ -679,6 +679,7 @@ void cpu_single_step(CPUState *cpu, int enabled);/* 0x08 currently unused */ #define BP_GDB 0x10#define BP_CPU 0x20 +#define BP_ANY (BP_GDB | BP_CPU)#define BP_WATCHPOINT_HIT_READ 0x40#define BP_WATCHPOINT_HIT_WRITE 0x80#define BP_WATCHPOINT_HIT (BP_WATCHPOINT_HIT_READ | BP_WATCHPOINT_HIT_WRITE)
@@ -689,6 +690,21 @@ int cpu_breakpoint_remove(CPUState *cpu, vaddr pc, int flags);void cpu_breakpoint_remove_by_ref (CPUState *cpu,CPUBreakpoint *breakpoint);void cpu_breakpoint_remove_all (CPUState *cpu,int mask); +/* Return true if PC matches an installed breakpoint. */ +static inline bool cpu_breakpoint_test (CPUState *cpu,vaddr pc,int mask) +{ +CPUBreakpoint *bp; + +if (unlikely (!QTAILQ_EMPTY (&cpu->breakpoints))) { + QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) { +if (bp->pc == pc && (bp->flags & mask)) { +return true; + } + } + } +return false; +} +int cpu_watchpoint_insert (CPUState *cpu,vaddr addr,vaddr len,int flags,CPUWatchpoint **watchpoint); int cpu_watchpoint_remove(CPUState *cpu, vaddr addr,
target-alpha/translate.c +4 -9
@@ -2868,7 +2868,6 @@ static inline void gen_intermediate_code_internal(AlphaCPU *cpu,target_ulong pc_start;target_ulong pc_mask;uint32_t insn; -CPUBreakpoint *bp;int j, lj =-1 ;ExitStatus ret;int num_insns;
@@ -2913,14 +2912,6 @@ static inline void gen_intermediate_code_internal(AlphaCPU *cpu,gen_tb_start (tb); do { - if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { - if (bp->pc == ctx.pc) { - gen_excp(&ctx, EXCP_DEBUG, 0); - break; - } - } - } if (search_pc) { j = tcg_op_buf_count(); if (lj < j) {
@@ -2936,6 +2927,10 @@ static inline void gen_intermediate_code_internal(AlphaCPU *cpu,tcg_gen_insn_start (ctx.pc); num_insns++; +if (unlikely (cpu_breakpoint_test (cs, ctx.pc,BP_ANY ))) { +gen_excp (&ctx,EXCP_DEBUG ,0 ); +break ; + }if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
target-arm/translate-a64.c +13 -13
@@ -11007,7 +11007,6 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,CPUState *cs =CPU (cpu);CPUARMState *env = &cpu->env;DisasContext dc1, *dc = &dc1; -CPUBreakpoint *bp;int j, lj;target_ulong pc_start;target_ulong next_page_start;
@@ -11079,18 +11078,6 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,tcg_clear_temp_count (); do { - if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { - if (bp->pc == dc->pc) { - gen_exception_internal_insn(dc, 0, EXCP_DEBUG); - /* Advance PC so that clearing the breakpoint will - invalidate this TB. */ - dc->pc += 2; - goto done_generating; - } - } - } - if (search_pc) { j = tcg_op_buf_count(); if (lj < j) {
@@ -11106,6 +11093,19 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,tcg_gen_insn_start (dc->pc); num_insns++; +if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) { +CPUBreakpoint *bp; + QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { +if (bp->pc == dc->pc) { +gen_exception_internal_insn (dc,0 ,EXCP_DEBUG ); +/* Advance PC so that clearing the breakpoint will +invalidate this TB. */ + dc->pc +=2 ; + goto done_generating; + } + } + } +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
target-arm/translate.c +16 -15
@@ -11177,7 +11177,6 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,CPUState *cs =CPU (cpu);CPUARMState *env = &cpu->env;DisasContext dc1, *dc = &dc1; -CPUBreakpoint *bp;int j, lj;target_ulong pc_start;target_ulong next_page_start;
@@ -11306,6 +11305,21 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,store_cpu_field (tmp, condexec_bits); } do { + if (search_pc) { + j = tcg_op_buf_count(); + if (lj < j) { + lj++; + while (lj < j) + tcg_ctx.gen_opc_instr_start[lj++] = 0; + } + tcg_ctx.gen_opc_pc[lj] = dc->pc; + gen_opc_condexec_bits[lj] = (dc->condexec_cond << 4) | (dc->condexec_mask >> 1); + tcg_ctx.gen_opc_instr_start[lj] = 1; + tcg_ctx.gen_opc_icount[lj] = num_insns; + } + tcg_gen_insn_start(dc->pc); + num_insns++; + #ifdef CONFIG_USER_ONLY /* Intercept jump to the magic kernel page. */ if (dc->pc >= 0xffff0000) {
@@ -11326,6 +11340,7 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,#endif if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) { +CPUBreakpoint *bp; QTAILQ_FOREACH(bp, &cs->breakpoints, entry) {if (bp->pc == dc->pc) {gen_exception_internal_insn (dc,0 ,EXCP_DEBUG );
@@ -11336,20 +11351,6 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu, } } } -if (search_pc) { - j =tcg_op_buf_count (); -if (lj < j) { - lj++; -while (lj < j) - tcg_ctx.gen_opc_instr_start[lj++] =0 ; - } - tcg_ctx.gen_opc_pc[lj] = dc->pc; - gen_opc_condexec_bits[lj] = (dc->condexec_cond <<4 ) | (dc->condexec_mask >>1 ); - tcg_ctx.gen_opc_instr_start[lj] =1 ; - tcg_ctx.gen_opc_icount[lj] = num_insns; - } -tcg_gen_insn_start (dc->pc); - num_insns++;if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start ();
target-cris/translate.c +8 -19
@@ -3030,23 +3030,6 @@ static unsigned int crisv32_decoder(CPUCRISState *env, DisasContext *dc)return insn_len; } -static void check_breakpoint (CPUCRISState *env,DisasContext *dc) -{ -CPUState *cs =CPU (cris_env_get_cpu (env)); -CPUBreakpoint *bp; - -if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { -if (bp->pc == dc->pc) { -cris_evaluate_flags (dc); -tcg_gen_movi_tl (env_pc, dc->pc); -t_gen_raise_exception (EXCP_DEBUG ); - dc->is_jmp =DISAS_UPDATE ; - } - } - } -} -#include "translate_v10.c" /*
@@ -3175,8 +3158,6 @@ gen_intermediate_code_internal(CRISCPU *cpu, TranslationBlock *tb,gen_tb_start (tb); do { - check_breakpoint(env, dc); - if (search_pc) { j = tcg_op_buf_count(); if (lj < j) {
@@ -3196,6 +3177,14 @@ gen_intermediate_code_internal(CRISCPU *cpu, TranslationBlock *tb,tcg_gen_insn_start (dc->pc); num_insns++; +if (unlikely (cpu_breakpoint_test (cs, dc->pc,BP_ANY ))) { +cris_evaluate_flags (dc); +tcg_gen_movi_tl (env_pc, dc->pc); +t_gen_raise_exception (EXCP_DEBUG ); + dc->is_jmp =DISAS_UPDATE ; +break ; + } +/* Pretty disas. */ LOG_DIS ("%8.8x:\t" , dc->pc);
target-i386/translate.c +7 -10
@@ -7849,7 +7849,6 @@ static inline void gen_intermediate_code_internal(X86CPU *cpu,CPUX86State *env = &cpu->env;DisasContext dc1, *dc = &dc1;target_ulong pc_ptr; -CPUBreakpoint *bp;int j, lj;uint64_t flags;target_ulong pc_start;
@@ -7938,15 +7937,6 @@ static inline void gen_intermediate_code_internal(X86CPU *cpu,gen_tb_start (tb);for (;;) { -if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { -if (bp->pc == pc_ptr && - !((bp->flags &BP_CPU ) && (tb->flags &HF_RF_MASK ))) { -gen_debug (dc, pc_ptr - dc->cs_base); - goto done_generating; - } - } - }if (search_pc) { j =tcg_op_buf_count ();if (lj < j) {
@@ -7962,6 +7952,13 @@ static inline void gen_intermediate_code_internal(X86CPU *cpu,tcg_gen_insn_start (pc_ptr); num_insns++; +/* If RF is set, suppress an internally generated breakpoint. */ +if (unlikely (cpu_breakpoint_test (cs, pc_ptr, + tb->flags &HF_RF_MASK + ?BP_GDB :BP_ANY ))) { +gen_debug (dc, pc_ptr - dc->cs_base); + goto done_generating; + }if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
target-lm32/translate.c +7 -18
@@ -1032,22 +1032,6 @@ static inline void decode(DisasContext *dc, uint32_t ir) decinfo[dc->opcode](dc); } -static void check_breakpoint (CPULM32State *env,DisasContext *dc) -{ -CPUState *cs =CPU (lm32_env_get_cpu (env)); -CPUBreakpoint *bp; - -if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { -if (bp->pc == dc->pc) { -tcg_gen_movi_tl (cpu_pc, dc->pc); -t_gen_raise_exception (dc,EXCP_DEBUG ); - dc->is_jmp =DISAS_UPDATE ; - } - } - } -} -/* generate intermediate code for basic block 'tb'. */ static inline void gen_intermediate_code_internal(LM32CPU *cpu,
@@ -1088,8 +1072,6 @@ void gen_intermediate_code_internal(LM32CPU *cpu,gen_tb_start (tb); do { - check_breakpoint(env, dc); - if (search_pc) { j = tcg_op_buf_count(); if (lj < j) {
@@ -1105,6 +1087,13 @@ void gen_intermediate_code_internal(LM32CPU *cpu,tcg_gen_insn_start (dc->pc); num_insns++; +if (unlikely (cpu_breakpoint_test (cs, dc->pc,BP_ANY ))) { +tcg_gen_movi_tl (cpu_pc, dc->pc); +t_gen_raise_exception (dc,EXCP_DEBUG ); + dc->is_jmp =DISAS_UPDATE ; +break ; + } +/* Pretty disas. */ LOG_DIS ("%8.8x:\t" , dc->pc);
target-m68k/translate.c +6 -12
@@ -2969,7 +2969,6 @@ gen_intermediate_code_internal(M68kCPU *cpu, TranslationBlock *tb,CPUState *cs =CPU (cpu);CPUM68KState *env = &cpu->env;DisasContext dc1, *dc = &dc1; -CPUBreakpoint *bp;int j, lj;target_ulong pc_start;int pc_offset;
@@ -2999,17 +2998,6 @@ gen_intermediate_code_internal(M68kCPU *cpu, TranslationBlock *tb, do { pc_offset = dc->pc - pc_start; gen_throws_exception = NULL; - if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { - if (bp->pc == dc->pc) { - gen_exception(dc, dc->pc, EXCP_DEBUG); - dc->is_jmp = DISAS_JUMP; - break; - } - } - if (dc->is_jmp) - break; - } if (search_pc) { j = tcg_op_buf_count(); if (lj < j) {
@@ -3024,6 +3012,12 @@ gen_intermediate_code_internal(M68kCPU *cpu, TranslationBlock *tb,tcg_gen_insn_start (dc->pc); num_insns++; +if (unlikely (cpu_breakpoint_test (cs, dc->pc,BP_ANY ))) { +gen_exception (dc, dc->pc,EXCP_DEBUG ); + dc->is_jmp =DISAS_JUMP ; +break ; + } +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
target-microblaze/translate.c +13 -23
@@ -1626,21 +1626,6 @@ static inline void decode(DisasContext *dc, uint32_t ir) } } -static void check_breakpoint (CPUMBState *env,DisasContext *dc) -{ -CPUState *cs =CPU (mb_env_get_cpu (env)); -CPUBreakpoint *bp; - -if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { -if (bp->pc == dc->pc) { -t_gen_raise_exception (dc,EXCP_DEBUG ); - dc->is_jmp =DISAS_UPDATE ; - } - } - } -} -/* generate intermediate code for basic block 'tb'. */ static inline void gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb,
@@ -1695,14 +1680,6 @@ gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb,gen_tb_start (tb); do { -#if SIM_COMPAT - if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { - tcg_gen_movi_tl(cpu_SR[SR_PC], dc->pc); - gen_helper_debug(); - } -#endif - check_breakpoint(env, dc); - if (search_pc) { j = tcg_op_buf_count(); if (lj < j) {
@@ -1717,6 +1694,19 @@ gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb,tcg_gen_insn_start (dc->pc); num_insns++; +#if SIM_COMPAT +if (qemu_loglevel_mask (CPU_LOG_TB_IN_ASM )) { +tcg_gen_movi_tl (cpu_SR[SR_PC ], dc->pc); +gen_helper_debug (); + } +#endif + +if (unlikely (cpu_breakpoint_test (cs, dc->pc,BP_ANY ))) { +t_gen_raise_exception (dc,EXCP_DEBUG ); + dc->is_jmp =DISAS_UPDATE ; +break ; + } +/* Pretty disas. */ LOG_DIS ("%8.8x:\t" , dc->pc);
target-mips/translate.c +10 -15
@@ -19544,7 +19544,6 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,DisasContext ctx;target_ulong pc_start;target_ulong next_page_start; -CPUBreakpoint *bp;int j, lj =-1 ;int num_insns;int max_insns;
@@ -19591,20 +19590,6 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,LOG_DISAS ("\ntb %p idx %d hflags %04x\n" , tb, ctx.mem_idx, ctx.hflags);gen_tb_start (tb);while (ctx.bstate ==BS_NONE ) { -if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { -if (bp->pc == ctx.pc) { -save_cpu_state (&ctx,1 ); - ctx.bstate =BS_BRANCH ; -gen_helper_raise_exception_debug (cpu_env); -/* Include the breakpoint location or the tb won't -* be flushed when it must be. */ - ctx.pc +=4 ; - goto done_generating; - } - } - } -if (search_pc) { j =tcg_op_buf_count ();if (lj < j) {
@@ -19621,6 +19606,16 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,tcg_gen_insn_start (ctx.pc); num_insns++; +if (unlikely (cpu_breakpoint_test (cs, ctx.pc,BP_ANY ))) { +save_cpu_state (&ctx,1 ); + ctx.bstate =BS_BRANCH ; +gen_helper_raise_exception_debug (cpu_env); +/* Include the breakpoint location or the tb won't +* be flushed when it must be. */ + ctx.pc +=4 ; + goto done_generating; + } +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
target-moxie/translate.c +7 -12
@@ -822,7 +822,6 @@ gen_intermediate_code_internal(MoxieCPU *cpu, TranslationBlock *tb,CPUState *cs =CPU (cpu);DisasContext ctx;target_ulong pc_start; -CPUBreakpoint *bp;int j, lj =-1 ;CPUMoxieState *env = &cpu->env;int num_insns;
@@ -838,17 +837,6 @@ gen_intermediate_code_internal(MoxieCPU *cpu, TranslationBlock *tb,gen_tb_start (tb); do { - if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { - if (ctx.pc == bp->pc) { - tcg_gen_movi_i32(cpu_pc, ctx.pc); - gen_helper_debug(cpu_env); - ctx.bstate = BS_EXCP; - goto done_generating; - } - } - } - if (search_pc) { j = tcg_op_buf_count(); if (lj < j) {
@@ -864,6 +852,13 @@ gen_intermediate_code_internal(MoxieCPU *cpu, TranslationBlock *tb,tcg_gen_insn_start (ctx.pc); num_insns++; +if (unlikely (cpu_breakpoint_test (cs, ctx.pc,BP_ANY ))) { +tcg_gen_movi_i32 (cpu_pc, ctx.pc); +gen_helper_debug (cpu_env); + ctx.bstate =BS_EXCP ; + goto done_generating; + } + ctx.opcode =cpu_lduw_code (env, ctx.pc); ctx.pc +=decode_opc (cpu, &ctx);
target-openrisc/translate.c +7 -17
@@ -1618,22 +1618,6 @@ static void disas_openrisc_insn(DisasContext *dc, OpenRISCCPU *cpu) } } -static void check_breakpoint (OpenRISCCPU *cpu,DisasContext *dc) -{ -CPUState *cs =CPU (cpu); -CPUBreakpoint *bp; - -if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { -if (bp->pc == dc->pc) { -tcg_gen_movi_tl (cpu_pc, dc->pc); -gen_exception (dc,EXCP_DEBUG ); - dc->is_jmp =DISAS_UPDATE ; - } - } - } -} -static inline void gen_intermediate_code_internal (OpenRISCCPU *cpu,TranslationBlock *tb,int search_pc)
@@ -1674,7 +1658,6 @@ static inline void gen_intermediate_code_internal(OpenRISCCPU *cpu,gen_tb_start (tb); do { - check_breakpoint(cpu, dc); if (search_pc) { j = tcg_op_buf_count(); if (k < j) {
@@ -1690,6 +1673,13 @@ static inline void gen_intermediate_code_internal(OpenRISCCPU *cpu,tcg_gen_insn_start (dc->pc); num_insns++; +if (unlikely (cpu_breakpoint_test (cs, dc->pc,BP_ANY ))) { +tcg_gen_movi_tl (cpu_pc, dc->pc); +gen_exception (dc,EXCP_DEBUG ); + dc->is_jmp =DISAS_UPDATE ; +break ; + } +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
target-ppc/translate.c +5 -9
@@ -11418,7 +11418,6 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,DisasContext ctx, *ctxp = &ctx;opc_handler_t **table, *handler;target_ulong pc_start; -CPUBreakpoint *bp;int j, lj =-1 ;int num_insns;int max_insns;
@@ -11483,14 +11482,6 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,tcg_clear_temp_count ();/* Set env in case of segfault during code fetch */ while (ctx.exception ==POWERPC_EXCP_NONE && !tcg_op_buf_full ()) { -if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { -if (bp->pc == ctx.nip) { -gen_debug_exception (ctxp); -break ; - } - } - }if (unlikely (search_pc)) { j =tcg_op_buf_count ();if (lj < j) {
@@ -11505,6 +11496,11 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,tcg_gen_insn_start (ctx.nip); num_insns++; +if (unlikely (cpu_breakpoint_test (cs, ctx.nip,BP_ANY ))) { +gen_debug_exception (ctxp); +break ; + } +LOG_DISAS ("----------------\n" );LOG_DISAS ("nip=" TARGET_FMT_lx" super=%d ir=%d\n" , ctx.nip, ctx.mem_idx, (int )msr_ir);
target-s390x/translate.c +6 -10
@@ -5330,7 +5330,6 @@ static inline void gen_intermediate_code_internal(S390CPU *cpu,uint64_t next_page_start;int j, lj =-1 ;int num_insns, max_insns; -CPUBreakpoint *bp;ExitStatus status;bool do_debug;
@@ -5373,20 +5372,17 @@ static inline void gen_intermediate_code_internal(S390CPU *cpu,tcg_gen_insn_start (dc.pc); num_insns++; +if (unlikely (cpu_breakpoint_test (cs, dc.pc,BP_ANY ))) { + status =EXIT_PC_STALE ; + do_debug = true; +break ; + } +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); } status =NO_EXIT ; -if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { -if (bp->pc == dc.pc) { - status =EXIT_PC_STALE ; - do_debug = true; -break ; - } - } - }if (status ==NO_EXIT ) { status =translate_one (env, &dc); }
target-sh4/translate.c +8 -12
@@ -1824,7 +1824,6 @@ gen_intermediate_code_internal(SuperHCPU *cpu, TranslationBlock *tb,CPUSH4State *env = &cpu->env;DisasContext ctx;target_ulong pc_start; -CPUBreakpoint *bp;int i, ii;int num_insns;int max_insns;
@@ -1849,17 +1848,6 @@ gen_intermediate_code_internal(SuperHCPU *cpu, TranslationBlock *tb, max_insns =CF_COUNT_MASK ;gen_tb_start (tb);while (ctx.bstate ==BS_NONE && !tcg_op_buf_full ()) { -if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { -if (ctx.pc == bp->pc) { -/* We have hit a breakpoint - make sure PC is up-to-date */ -tcg_gen_movi_i32 (cpu_pc, ctx.pc); -gen_helper_debug (cpu_env); - ctx.bstate =BS_BRANCH ; -break ; - } - } - }if (search_pc) { i =tcg_op_buf_count ();if (ii < i) {
@@ -1875,6 +1863,14 @@ gen_intermediate_code_internal(SuperHCPU *cpu, TranslationBlock *tb,tcg_gen_insn_start (ctx.pc); num_insns++; +if (unlikely (cpu_breakpoint_test (cs, ctx.pc,BP_ANY ))) { +/* We have hit a breakpoint - make sure PC is up-to-date */ +tcg_gen_movi_i32 (cpu_pc, ctx.pc); +gen_helper_debug (cpu_env); + ctx.bstate =BS_BRANCH ; +break ; + } +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
target-sparc/translate.c +10 -13
@@ -5217,7 +5217,6 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu,CPUSPARCState *env = &cpu->env;target_ulong pc_start, last_pc;DisasContext dc1, *dc = &dc1; -CPUBreakpoint *bp;int j, lj =-1 ;int num_insns;int max_insns;
@@ -5242,18 +5241,6 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu, max_insns =CF_COUNT_MASK ;gen_tb_start (tb); do { - if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { - if (bp->pc == dc->pc) { - if (dc->pc != pc_start) - save_state(dc); - gen_helper_debug(cpu_env); - tcg_gen_exit_tb(0); - dc->is_br = 1; - goto exit_gen_loop; - } - } - } if (spc) { qemu_log("Search PC...\n"); j = tcg_op_buf_count();
@@ -5270,6 +5257,16 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu,tcg_gen_insn_start (dc->pc); num_insns++; +if (unlikely (cpu_breakpoint_test (cs, dc->pc,BP_ANY ))) { +if (dc->pc != pc_start) { +save_state (dc); + } +gen_helper_debug (cpu_env); +tcg_gen_exit_tb (0 ); + dc->is_br =1 ; + goto exit_gen_loop; + } +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
target-unicore32/translate.c +10 -14
@@ -1872,7 +1872,6 @@ static inline void gen_intermediate_code_internal(UniCore32CPU *cpu,CPUState *cs =CPU (cpu);CPUUniCore32State *env = &cpu->env;DisasContext dc1, *dc = &dc1; -CPUBreakpoint *bp;int j, lj;target_ulong pc_start;uint32_t next_page_start;
@@ -1912,19 +1911,6 @@ static inline void gen_intermediate_code_internal(UniCore32CPU *cpu,gen_tb_start (tb); do { - if (unlikely(!QTAILQ_EMPTY(&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { - if (bp->pc == dc->pc) { - gen_set_pc_im(dc->pc); - gen_exception(EXCP_DEBUG); - dc->is_jmp = DISAS_JUMP; - /* Advance PC so that clearing the breakpoint will - invalidate this TB. */ - dc->pc += 2; /* FIXME */ - goto done_generating; - } - } - } if (search_pc) { j = tcg_op_buf_count(); if (lj < j) {
@@ -1940,6 +1926,16 @@ static inline void gen_intermediate_code_internal(UniCore32CPU *cpu,tcg_gen_insn_start (dc->pc); num_insns++; +if (unlikely (cpu_breakpoint_test (cs, dc->pc,BP_ANY ))) { +gen_set_pc_im (dc->pc); +gen_exception (EXCP_DEBUG ); + dc->is_jmp =DISAS_JUMP ; +/* Advance PC so that clearing the breakpoint will +invalidate this TB. */ + dc->pc +=2 ;/* FIXME */ + goto done_generating; + } +if (num_insns == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
target-xtensa/translate.c +7 -18
@@ -2984,22 +2984,6 @@ static inline unsigned xtensa_insn_len(CPUXtensaState *env, DisasContext *dc)return xtensa_op0_insn_len (OP0 ); } -static void check_breakpoint (CPUXtensaState *env,DisasContext *dc) -{ -CPUState *cs =CPU (xtensa_env_get_cpu (env)); -CPUBreakpoint *bp; - -if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) { - QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { -if (bp->pc == dc->pc) { -tcg_gen_movi_i32 (cpu_pc, dc->pc); -gen_exception (dc,EXCP_DEBUG ); - dc->is_jmp =DISAS_UPDATE ; - } - } - } -} -static void gen_ibreak_check (CPUXtensaState *env,DisasContext *dc) {unsigned i;
@@ -3062,8 +3046,6 @@ void gen_intermediate_code_internal(XtensaCPU *cpu, } do { - check_breakpoint(env, &dc); - if (search_pc) { j = tcg_op_buf_count(); if (lj < j) {
@@ -3081,6 +3063,13 @@ void gen_intermediate_code_internal(XtensaCPU *cpu, ++dc.ccount_delta; +if (unlikely (cpu_breakpoint_test (cs, dc.pc,BP_ANY ))) { +tcg_gen_movi_i32 (cpu_pc, dc.pc); +gen_exception (&dc,EXCP_DEBUG ); + dc.is_jmp =DISAS_UPDATE ; +break ; + } +if (insn_count == max_insns && (tb->cflags &CF_LAST_IO )) {gen_io_start (); }
Signature · 1 line
2.4.3
PATCH v4 5/26 tcg: Allow extra data to be attached to insn_start
In reply to Richard HendersonWith an eye toward having this data replace the gen_opc_* arrays that each target collects in order to enable restore_state_from_tb.
--- tcg/tcg-op.h | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- tcg/tcg-opc.h | 4 ++-- tcg/tcg.c | 13 +++++++------ tcg/tcg.h | 6 ++++++ 4 files changed, 59 insertions(+), 16 deletions(-)
tcg/tcg-op.h +44 -8
@@ -700,17 +700,53 @@ static inline void tcg_gen_concat32_i64(TCGv_i64 ret, TCGv_i64 lo, TCGv_i64 hi)#error must include QEMU headers#endif -/* debug info: write the PC of the corresponding QEMU CPU instruction */ -static inline void tcg_gen_insn_start (uint64_t pc) +#if TARGET_INSN_START_WORDS ==1 +# if TARGET_LONG_BITS <=TCG_TARGET_REG_BITS +static inline void tcg_gen_insn_start (target_ulong pc) { -/* XXX: must really use a 32 bit size for TCGArg in all cases */ -#if TARGET_LONG_BITS >TCG_TARGET_REG_BITS -tcg_gen_op2ii (INDEX_op_insn_start, - (uint32_t )(pc), (uint32_t )(pc >>32 )); +tcg_gen_op1 (&tcg_ctx, INDEX_op_insn_start, pc); +} +# else +static inline void tcg_gen_insn_start (target_ulong pc) +{ +tcg_gen_op2 (&tcg_ctx, INDEX_op_insn_start, + (uint32_t )pc, (uint32_t )(pc >>32 )); +} +# endif +#elif TARGET_INSN_START_WORDS ==2 +# if TARGET_LONG_BITS <=TCG_TARGET_REG_BITS +static inline void tcg_gen_insn_start (target_ulong pc,target_ulong a1) +{ +tcg_gen_op2 (&tcg_ctx, INDEX_op_insn_start, pc, a1); +} +# else +static inline void tcg_gen_insn_start (target_ulong pc,target_ulong a1) +{ +tcg_gen_op4 (&tcg_ctx, INDEX_op_insn_start, + (uint32_t )pc, (uint32_t )(pc >>32 ), + (uint32_t )a1, (uint32_t )(a1 >>32 )); +} +# endif +#elif TARGET_INSN_START_WORDS ==3 +# if TARGET_LONG_BITS <=TCG_TARGET_REG_BITS +static inline void tcg_gen_insn_start (target_ulong pc,target_ulong a1, +target_ulong a2) +{ +tcg_gen_op3 (&tcg_ctx, INDEX_op_insn_start, pc, a1, a2); +} +# else +static inline void tcg_gen_insn_start (target_ulong pc,target_ulong a1, +target_ulong a2) +{ +tcg_gen_op6 (&tcg_ctx, INDEX_op_insn_start, + (uint32_t )pc, (uint32_t )(pc >>32 ), + (uint32_t )a1, (uint32_t )(a1 >>32 ), + (uint32_t )a2, (uint32_t )(a2 >>32 )); +} +# endif #else -tcg_gen_op1i (INDEX_op_insn_start, pc); +# error "Unhandled number of operands to insn_start"#endif -}static inline void tcg_gen_exit_tb (uintptr_t val) {
tcg/tcg-opc.h +2 -2
@@ -175,9 +175,9 @@ DEF(mulsh_i64, 1, 2, 0, IMPL(TCG_TARGET_HAS_mulsh_i64))/* QEMU specific */ #if TARGET_LONG_BITS >TCG_TARGET_REG_BITS -DEF(insn_start, 0, 0, 2, TCG_OPF_NOT_PRESENT) +DEF(insn_start, 0, 0, 2 * TARGET_INSN_START_WORDS, TCG_OPF_NOT_PRESENT)#else -DEF(insn_start, 0, 0, 1, TCG_OPF_NOT_PRESENT) +DEF(insn_start, 0, 0, TARGET_INSN_START_WORDS, TCG_OPF_NOT_PRESENT)#endif DEF(exit_tb, 0, 0, 1, TCG_OPF_BB_END)DEF (goto_tb,0 ,0 ,1 ,TCG_OPF_BB_END )
tcg/tcg.c +7 -6
@@ -991,16 +991,17 @@ void tcg_dump_ops(TCGContext *s) args = &s->gen_opparam_buf[op->args];if (c == INDEX_op_insn_start) { -uint64_t pc; +qemu_log ("%s ----" , oi != s->gen_first_op_idx ?"\n" :"" ); + +for (i =0 ; i <TARGET_INSN_START_WORDS ; ++i) { +target_ulong a;#if TARGET_LONG_BITS >TCG_TARGET_REG_BITS - pc = ((uint64_t )args[1 ] <<32 ) | args[0 ]; + a = ((target_ulong )args[i *2 +1 ] <<32 ) | args[i *2 ];#else - pc = args[0 ]; + a = args[i];#endif -if (oi != s->gen_first_op_idx) { -qemu_log ("\n" ); +qemu_log (" " TARGET_FMT_lx, a); } -qemu_log (" ---- 0x%" PRIx64, pc); }else if (c == INDEX_op_call) {/* variable number of arguments */ nb_oargs = op->callo;
tcg/tcg.h +6 -0
@@ -129,6 +129,12 @@ typedef uint64_t TCGRegSet;# error "Missing unsigned widening multiply"#endif +#ifndef TARGET_INSN_START_EXTRA_WORDS +# define TARGET_INSN_START_WORDS 1 +#else +# define TARGET_INSN_START_WORDS (1 + TARGET_INSN_START_EXTRA_WORDS) +#endif + typedef enum TCGOpcode { #define DEF(name, oargs, iargs, cargs, flags) INDEX_op_ ## name,#include "tcg-opc.h"
Signature · 1 line
2.4.3
PATCH v4 6/26 target-arm: Add condexec state to insn_start
In reply to Richard Henderson--- target-arm/cpu.h | 1 + target-arm/translate-a64.c | 2 +- target-arm/translate.c | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-)
target-arm/cpu.h +1 -0
@@ -95,6 +95,7 @@struct arm_boot_info ;#define NB_MMU_MODES 7 +#define TARGET_INSN_START_EXTRA_WORDS 1/* We currently assume float and double are IEEE single and double precision respectively.
target-arm/translate-a64.c +1 -1
@@ -11090,7 +11090,7 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } -tcg_gen_insn_start (dc->pc); +tcg_gen_insn_start (dc->pc,0 ); num_insns++;if (unlikely (!QTAILQ_EMPTY (&cs->breakpoints))) {
target-arm/translate.c +2 -1
@@ -11317,7 +11317,8 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } -tcg_gen_insn_start (dc->pc); +tcg_gen_insn_start (dc->pc, + (dc->condexec_cond <<4 ) | (dc->condexec_mask >>1 )); num_insns++;#ifdef CONFIG_USER_ONLY
Signature · 1 line
2.4.3
PATCH v4 7/26 target-i386: Add cc_op state to insn_start
In reply to Richard Henderson--- target-i386/cpu.h | 1 + target-i386/translate.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
target-i386/cpu.h +1 -0
@@ -794,6 +794,7 @@ typedef struct {#define MAX_GP_COUNTERS (MSR_IA32_PERF_STATUS - MSR_P6_EVNTSEL0)#define NB_MMU_MODES 3 +#define TARGET_INSN_START_EXTRA_WORDS 1#define NB_OPMASK_REGS 8
target-i386/translate.c +1 -1
@@ -7949,7 +7949,7 @@ static inline void gen_intermediate_code_internal(X86CPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } -tcg_gen_insn_start (pc_ptr); +tcg_gen_insn_start (pc_ptr, dc->cc_op); num_insns++;/* If RF is set, suppress an internally generated breakpoint. */
Signature · 1 line
2.4.3
PATCH v4 8/26 target-mips: Add delayed branch state to insn_start
In reply to Richard Henderson--- target-mips/cpu.h | 1 + target-mips/translate.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
target-mips/cpu.h +1 -0
@@ -130,6 +130,7 @@ struct CPUMIPSFPUContext { };#define NB_MMU_MODES 3 +#define TARGET_INSN_START_EXTRA_WORDS 2typedef struct CPUMIPSMVPContext CPUMIPSMVPContext ;struct CPUMIPSMVPContext {
target-mips/translate.c +2 -1
@@ -19562,6 +19562,7 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb, ctx.CP0_Config1 = env->CP0_Config1; ctx.tb = tb; ctx.bstate =BS_NONE ; + ctx.btarget =0 ; ctx.kscrexist = (env->CP0_Config4 >> CP0C4_KScrExist) &0xff ; ctx.rxi = (env->CP0_Config3 >>CP0C3_RXI ) &1 ; ctx.ie = (env->CP0_Config4 >>CP0C4_IE ) &3 ;
@@ -19603,7 +19604,7 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } -tcg_gen_insn_start (ctx.pc); +tcg_gen_insn_start (ctx.pc, ctx.hflags &MIPS_HFLAG_BMASK , ctx.btarget); num_insns++;if (unlikely (cpu_breakpoint_test (cs, ctx.pc,BP_ANY ))) {
Signature · 1 line
2.4.3
PATCH v4 9/26 target-s390x: Add cc_op state to insn_start
In reply to Richard Henderson--- target-s390x/cpu.h | 1 + target-s390x/translate.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
target-s390x/cpu.h +1 -0
@@ -42,6 +42,7 @@#include "fpu/softfloat.h" #define NB_MMU_MODES 3 +#define TARGET_INSN_START_EXTRA_WORDS 1#define MMU_MODE0_SUFFIX _primary#define MMU_MODE1_SUFFIX _secondary
target-s390x/translate.c +1 -1
@@ -5369,7 +5369,7 @@ static inline void gen_intermediate_code_internal(S390CPU *cpu, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } -tcg_gen_insn_start (dc.pc); +tcg_gen_insn_start (dc.pc, dc.cc_op); num_insns++;if (unlikely (cpu_breakpoint_test (cs, dc.pc,BP_ANY ))) {
Signature · 1 line
2.4.3
PATCH v4 10/26 target-sh4: Add flags state to insn_start
In reply to Richard Henderson--- target-sh4/cpu.h | 1 + target-sh4/translate.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
target-sh4/cpu.h +1 -0
@@ -120,6 +120,7 @@ typedef struct tlb_t {#define ITLB_SIZE 4#define NB_MMU_MODES 2 +#define TARGET_INSN_START_EXTRA_WORDS 1enum sh_features {SH_FEATURE_SH4A =1 ,
target-sh4/translate.c +1 -1
@@ -1860,7 +1860,7 @@ gen_intermediate_code_internal(SuperHCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_instr_start[ii] =1 ; tcg_ctx.gen_opc_icount[ii] = num_insns; } -tcg_gen_insn_start (ctx.pc); +tcg_gen_insn_start (ctx.pc, ctx.flags); num_insns++;if (unlikely (cpu_breakpoint_test (cs, ctx.pc,BP_ANY ))) {
Signature · 1 line
2.4.3
PATCH v4 11/26 target-cris: Mirror gen_opc_pc into insn_start
In reply to Richard HendersonThis perhaps isn't ideal in terms of (ab)using the "pc" field to encode both pc and ppc + delay branch state, as one has to be aware of this when examining opcode dumps.
But it preserves existing logic, which will be good for bisection, and it certainly does save storage space.
--- target-cris/translate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target-cris/translate.c +2 -1
@@ -3174,7 +3174,8 @@ gen_intermediate_code_internal(CRISCPU *cpu, TranslationBlock *tb, tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; } -tcg_gen_insn_start (dc->pc); +tcg_gen_insn_start (dc->delayed_branch ==1 + ? dc->ppc |1 : dc->pc); num_insns++;if (unlikely (cpu_breakpoint_test (cs, dc->pc,BP_ANY ))) {
Signature · 1 line
2.4.3
PATCH v4 12/26 target-sparc: Tidy gen_branch_a interface
In reply to Richard HendersonWe always pass pc2 == dc->npc and r_cond == cpu_cond, and always set is_br afterward. Infer all of that.
--- target-sparc/translate.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
target-sparc/translate.c +10 -11
@@ -955,17 +955,19 @@ static inline void gen_branch2(DisasContext *dc, target_ulong pc1,gen_goto_tb (dc,1 , pc2, pc2 +4 ); } -static inline void gen_branch_a (DisasContext *dc,target_ulong pc1, -target_ulong pc2,TCGv r_cond) +static void gen_branch_a (DisasContext *dc,target_ulong pc1) {TCGLabel *l1 =gen_new_label (); +target_ulong npc = dc->npc; -tcg_gen_brcondi_tl (TCG_COND_EQ , r_cond,0 , l1); +tcg_gen_brcondi_tl (TCG_COND_EQ , cpu_cond,0 , l1); -gen_goto_tb (dc,0 , pc2, pc1); +gen_goto_tb (dc,0 , npc, pc1);gen_set_label (l1); -gen_goto_tb (dc,1 , pc2 +4 , pc2 +8 ); +gen_goto_tb (dc,1 , npc +4 , npc +8 ); + + dc->is_br =1 ; }static inline void gen_generic_branch (DisasContext *dc)
@@ -1398,8 +1400,7 @@ static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc)flush_cond (dc);gen_cond (cpu_cond, cc, cond, dc);if (a) { -gen_branch_a (dc, target, dc->npc, cpu_cond); - dc->is_br =1 ; +gen_branch_a (dc, target); }else { dc->pc = dc->npc; dc->jump_pc[0 ] = target;
@@ -1447,8 +1448,7 @@ static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc)flush_cond (dc);gen_fcond (cpu_cond, cc, cond);if (a) { -gen_branch_a (dc, target, dc->npc, cpu_cond); - dc->is_br =1 ; +gen_branch_a (dc, target); }else { dc->pc = dc->npc; dc->jump_pc[0 ] = target;
@@ -1476,8 +1476,7 @@ static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,flush_cond (dc);gen_cond_reg (cpu_cond, cond, r_reg);if (a) { -gen_branch_a (dc, target, dc->npc, cpu_cond); - dc->is_br =1 ; +gen_branch_a (dc, target); }else { dc->pc = dc->npc; dc->jump_pc[0 ] = target;
Signature · 1 line
2.4.3
PATCH v4 13/26 target-sparc: Split out gen_branch_n
In reply to Richard HendersonUnify three copies of this code from different branch types. Fix the case when npc == DYNAMIC_PC, i.e. a branch within a delay slot.
--- target-sparc/translate.c | 55 ++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 27 deletions(-)
target-sparc/translate.c +28 -27
@@ -970,6 +970,31 @@ static void gen_branch_a(DisasContext *dc, target_ulong pc1) dc->is_br =1 ; } +static void gen_branch_n (DisasContext *dc,target_ulong pc1) +{ +target_ulong npc = dc->npc; + +if (likely (npc !=DYNAMIC_PC )) { + dc->pc = npc; + dc->jump_pc[0 ] = pc1; + dc->jump_pc[1 ] = npc +4 ; + dc->npc =JUMP_PC ; + }else { +TCGv t, z; + +tcg_gen_mov_tl (cpu_pc, cpu_npc); + +tcg_gen_addi_tl (cpu_npc, cpu_npc,4 ); + t =tcg_const_tl (pc1); + z =tcg_const_tl (0 ); +tcg_gen_movcond_tl (TCG_COND_NE , cpu_npc, cpu_cond, z, t, cpu_npc); +tcg_temp_free (t); +tcg_temp_free (z); + + dc->pc =DYNAMIC_PC ; + } +} +static inline void gen_generic_branch (DisasContext *dc) {TCGv npc0 =tcg_const_tl (dc->jump_pc[0 ]);
@@ -1402,15 +1427,7 @@ static void do_branch(DisasContext *dc, int32_t offset, uint32_t insn, int cc)if (a) {gen_branch_a (dc, target); }else { - dc->pc = dc->npc; - dc->jump_pc[0 ] = target; -if (unlikely (dc->npc ==DYNAMIC_PC )) { - dc->jump_pc[1 ] =DYNAMIC_PC ; -tcg_gen_addi_tl (cpu_pc, cpu_npc,4 ); - }else { - dc->jump_pc[1 ] = dc->npc +4 ; - dc->npc =JUMP_PC ; - } +gen_branch_n (dc, target); } } }
@@ -1450,15 +1467,7 @@ static void do_fbranch(DisasContext *dc, int32_t offset, uint32_t insn, int cc)if (a) {gen_branch_a (dc, target); }else { - dc->pc = dc->npc; - dc->jump_pc[0 ] = target; -if (unlikely (dc->npc ==DYNAMIC_PC )) { - dc->jump_pc[1 ] =DYNAMIC_PC ; -tcg_gen_addi_tl (cpu_pc, cpu_npc,4 ); - }else { - dc->jump_pc[1 ] = dc->npc +4 ; - dc->npc =JUMP_PC ; - } +gen_branch_n (dc, target); } } }
@@ -1478,15 +1487,7 @@ static void do_branch_reg(DisasContext *dc, int32_t offset, uint32_t insn,if (a) {gen_branch_a (dc, target); }else { - dc->pc = dc->npc; - dc->jump_pc[0 ] = target; -if (unlikely (dc->npc ==DYNAMIC_PC )) { - dc->jump_pc[1 ] =DYNAMIC_PC ; -tcg_gen_addi_tl (cpu_pc, cpu_npc,4 ); - }else { - dc->jump_pc[1 ] = dc->npc +4 ; - dc->npc =JUMP_PC ; - } +gen_branch_n (dc, target); } }
Signature · 1 line
2.4.3
PATCH v4 14/26 target-sparc: Remove gen_opc_jump_pc
In reply to Richard HendersonSince jump_pc[1] is always npc + 4, we can infer after incrementing that jump_pc[1] == pc + 4. Because of that, we can encode the branch destination into a single word, and store that in npc.
--- target-sparc/translate.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
target-sparc/translate.c +10 -9
@@ -65,7 +65,6 @@ static TCGv cpu_wim;static TCGv_i64 cpu_fpr[TARGET_DPREGS ];static target_ulong gen_opc_npc[OPC_BUF_SIZE ]; -static target_ulong gen_opc_jump_pc[2 ];#include "exec/gen-icount.h"
@@ -5250,6 +5249,10 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu, tcg_ctx.gen_opc_instr_start[lj++] =0 ; tcg_ctx.gen_opc_pc[lj] = dc->pc; gen_opc_npc[lj] = dc->npc; +if (dc->npc &JUMP_PC ) { +assert (dc->jump_pc[1 ] == dc->pc +4 ); + gen_opc_npc[lj] = dc->jump_pc[0 ] |JUMP_PC ; + } tcg_ctx.gen_opc_instr_start[lj] =1 ; tcg_ctx.gen_opc_icount[lj] = num_insns; }
@@ -5321,8 +5324,6 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu,#if 0 log_page_dump ();#endif - gen_opc_jump_pc[0 ] = dc->jump_pc[0 ]; - gen_opc_jump_pc[1 ] = dc->jump_pc[1 ]; }else { tb->size = last_pc +4 - pc_start; tb->icount = num_insns;
@@ -5450,17 +5451,17 @@ void gen_intermediate_code_init(CPUSPARCState *env)void restore_state_to_opc (CPUSPARCState *env,TranslationBlock *tb,int pc_pos) { -target_ulong npc; - env->pc = tcg_ctx.gen_opc_pc[pc_pos]; +target_ulong pc, npc; + env->pc = pc = tcg_ctx.gen_opc_pc[pc_pos]; npc = gen_opc_npc[pc_pos]; -if (npc ==1 ) { +if (npc ==DYNAMIC_PC ) {/* dynamic NPC: already stored */ - }else if (npc ==2 ) { + }else if (npc &JUMP_PC ) {/* jump PC: use 'cond' and the jump targets of the translation */ if (env->cond) { - env->npc = gen_opc_jump_pc[0 ]; + env->npc = npc & ~3 ; }else { - env->npc = gen_opc_jump_pc[1 ]; + env->npc = pc +4 ; } }else { env->npc = npc;
Signature · 1 line
2.4.3
PATCH v4 15/26 target-sparc: Add npc state to insn_start
In reply to Richard Henderson--- target-sparc/cpu.h | 1 + target-sparc/translate.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-)
target-sparc/cpu.h +1 -0
@@ -230,6 +230,7 @@ typedef struct trap_state {uint32_t tt; } trap_state;#endif +#define TARGET_INSN_START_EXTRA_WORDS 1 typedef struct sparc_def_t { const char *name;
target-sparc/translate.c +6 -1
@@ -5257,7 +5257,12 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu, tcg_ctx.gen_opc_icount[lj] = num_insns; } } -tcg_gen_insn_start (dc->pc); +if (dc->npc &JUMP_PC ) { +assert (dc->jump_pc[1 ] == dc->pc +4 ); +tcg_gen_insn_start (dc->pc, dc->jump_pc[0 ] |JUMP_PC ); + }else { +tcg_gen_insn_start (dc->pc, dc->npc); + } num_insns++;if (unlikely (cpu_breakpoint_test (cs, dc->pc,BP_ANY ))) {
Signature · 1 line
2.4.3
PATCH v4 16/26 tcg: Merge cpu_gen_code into tb_gen_code
In reply to Richard HendersonAs it's only caller, this tidies things a bit.
--- include/exec/exec-all.h | 2 - translate-all.c | 131 ++++++++++++++++++++++-------------------------- 2 files changed, 59 insertions(+), 74 deletions(-)
include/exec/exec-all.h +0 -2
@@ -78,8 +78,6 @@ void restore_state_to_opc(CPUArchState *env, struct TranslationBlock *tb, int pc_pos);void cpu_gen_init (void ); -int cpu_gen_code (CPUArchState *env,struct TranslationBlock *tb, -int *gen_code_size_ptr);bool cpu_restore_state (CPUState *cpu,uintptr_t searched_pc);void page_size_init (void );
translate-all.c +59 -72
152 lines not on this page · raw message
Signature · 1 line
2.4.3
PATCH v4 17/26 target-*: Drop cpu_gen_code define
In reply to Richard HendersonThis symbol no longer exists.
--- target-alpha/cpu.h | 1 - target-arm/cpu.h | 1 - target-cris/cpu.h | 1 - target-i386/cpu.h | 1 - target-lm32/cpu.h | 1 - target-m68k/cpu.h | 1 - target-microblaze/cpu.h | 1 - target-mips/cpu.h | 1 - target-moxie/cpu.h | 1 - target-openrisc/cpu.h | 1 - target-ppc/cpu.h | 1 - target-s390x/cpu.h | 1 - target-sh4/cpu.h | 1 - target-sparc/cpu.h | 1 - target-tilegx/cpu.h | 1 - target-xtensa/cpu.h | 1 - 16 files changed, 16 deletions(-)
target-alpha/cpu.h +0 -1
@@ -287,7 +287,6 @@ struct CPUAlphaState {#define cpu_list alpha_cpu_list#define cpu_exec cpu_alpha_exec -#define cpu_gen_code cpu_alpha_gen_code#define cpu_signal_handler cpu_alpha_signal_handler#include "exec/cpu-all.h"
target-arm/cpu.h +0 -1
@@ -1601,7 +1601,6 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx,#define cpu_init (cpu_model) CPU(cpu_arm_init(cpu_model))#define cpu_exec cpu_arm_exec -#define cpu_gen_code cpu_arm_gen_code#define cpu_signal_handler cpu_arm_signal_handler#define cpu_list arm_cpu_list
target-cris/cpu.h +0 -1
@@ -223,7 +223,6 @@ enum {#define cpu_init (cpu_model) CPU(cpu_cris_init(cpu_model))#define cpu_exec cpu_cris_exec -#define cpu_gen_code cpu_cris_gen_code#define cpu_signal_handler cpu_cris_signal_handler/* MMU modes definitions */
target-i386/cpu.h +0 -1
@@ -1190,7 +1190,6 @@ uint64_t cpu_get_tsc(CPUX86State *env);#define cpu_init (cpu_model) CPU(cpu_x86_init(cpu_model))#define cpu_exec cpu_x86_exec -#define cpu_gen_code cpu_x86_gen_code#define cpu_signal_handler cpu_x86_signal_handler#define cpu_list x86_cpu_list#define cpudef_setup x86_cpudef_setup
target-lm32/cpu.h +0 -1
@@ -219,7 +219,6 @@ bool lm32_cpu_do_semihosting(CPUState *cs);#define cpu_list lm32_cpu_list#define cpu_exec cpu_lm32_exec -#define cpu_gen_code cpu_lm32_gen_code#define cpu_signal_handler cpu_lm32_signal_handler int lm32_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw,
target-m68k/cpu.h +0 -1
@@ -213,7 +213,6 @@ void register_m68k_insns (CPUM68KState *env);#define cpu_init (cpu_model) CPU(cpu_m68k_init(cpu_model))#define cpu_exec cpu_m68k_exec -#define cpu_gen_code cpu_m68k_gen_code#define cpu_signal_handler cpu_m68k_signal_handler#define cpu_list m68k_cpu_list
target-microblaze/cpu.h +0 -1
@@ -295,7 +295,6 @@ int cpu_mb_signal_handler(int host_signum, void *pinfo,#define cpu_init (cpu_model) CPU(cpu_mb_init(cpu_model))#define cpu_exec cpu_mb_exec -#define cpu_gen_code cpu_mb_gen_code#define cpu_signal_handler cpu_mb_signal_handler/* MMU modes definitions */
target-mips/cpu.h +0 -1
@@ -620,7 +620,6 @@ void mips_cpu_unassigned_access(CPUState *cpu, hwaddr addr,void mips_cpu_list (FILE *f,fprintf_function cpu_fprintf);#define cpu_exec cpu_mips_exec -#define cpu_gen_code cpu_mips_gen_code#define cpu_signal_handler cpu_mips_signal_handler#define cpu_list mips_cpu_list
target-moxie/cpu.h +0 -1
@@ -122,7 +122,6 @@ int cpu_moxie_signal_handler(int host_signum, void *pinfo,#define cpu_init (cpu_model) CPU(cpu_moxie_init(cpu_model))#define cpu_exec cpu_moxie_exec -#define cpu_gen_code cpu_moxie_gen_code#define cpu_signal_handler cpu_moxie_signal_handlerstatic inline int cpu_mmu_index (CPUMoxieState *env,bool ifetch)
target-openrisc/cpu.h +0 -1
@@ -360,7 +360,6 @@ int cpu_openrisc_signal_handler(int host_signum, void *pinfo, void *puc);#define cpu_list cpu_openrisc_list#define cpu_exec cpu_openrisc_exec -#define cpu_gen_code cpu_openrisc_gen_code#define cpu_signal_handler cpu_openrisc_signal_handler#ifndef CONFIG_USER_ONLY
target-ppc/cpu.h +0 -1
@@ -1241,7 +1241,6 @@ int ppc_dcr_write (ppc_dcr_t *dcr_env, int dcrn, uint32_t val);#define cpu_init (cpu_model) CPU(cpu_ppc_init(cpu_model))#define cpu_exec cpu_ppc_exec -#define cpu_gen_code cpu_ppc_gen_code#define cpu_signal_handler cpu_ppc_signal_handler#define cpu_list ppc_cpu_list
target-s390x/cpu.h +0 -1
@@ -598,7 +598,6 @@ bool css_present(uint8_t cssid);#define cpu_init (model) CPU(cpu_s390x_init(model))#define cpu_exec cpu_s390x_exec -#define cpu_gen_code cpu_s390x_gen_code#define cpu_signal_handler cpu_s390x_signal_handlervoid s390_cpu_list (FILE *f,fprintf_function cpu_fprintf);
target-sh4/cpu.h +0 -1
@@ -226,7 +226,6 @@ void cpu_load_tlb(CPUSH4State * env);#define cpu_init (cpu_model) CPU(cpu_sh4_init(cpu_model))#define cpu_exec cpu_sh4_exec -#define cpu_gen_code cpu_sh4_gen_code#define cpu_signal_handler cpu_sh4_signal_handler#define cpu_list sh4_cpu_list
target-sparc/cpu.h +0 -1
@@ -593,7 +593,6 @@ int cpu_sparc_signal_handler(int host_signum, void *pinfo, void *puc);#endif #define cpu_exec cpu_sparc_exec -#define cpu_gen_code cpu_sparc_gen_code#define cpu_signal_handler cpu_sparc_signal_handler#define cpu_list sparc_cpu_list
target-tilegx/cpu.h +0 -1
@@ -163,7 +163,6 @@ TileGXCPU *cpu_tilegx_init(const char *cpu_model);#define cpu_init (cpu_model) CPU(cpu_tilegx_init(cpu_model))#define cpu_exec cpu_tilegx_exec -#define cpu_gen_code cpu_tilegx_gen_code#define cpu_signal_handler cpu_tilegx_signal_handler static inline void cpu_get_tb_cpu_state(CPUTLGState *env, target_ulong *pc,
target-xtensa/cpu.h +0 -1
@@ -382,7 +382,6 @@ typedef struct CPUXtensaState {#include "cpu-qom.h" #define cpu_exec cpu_xtensa_exec -#define cpu_gen_code cpu_xtensa_gen_code#define cpu_signal_handler cpu_xtensa_signal_handler#define cpu_list xtensa_cpu_list
Signature · 1 line
2.4.3
PATCH v4 18/26 tcg: Add TCG_MAX_INSNS
In reply to Richard HendersonAdjust all translators to respect it.
--- target-alpha/translate.c | 3 +++ target-arm/translate-a64.c | 3 +++ target-arm/translate.c | 6 +++++- target-cris/translate.c | 3 +++ target-i386/translate.c | 6 +++++- target-lm32/translate.c | 3 +++ target-m68k/translate.c | 6 +++++- target-microblaze/translate.c | 6 +++++- target-mips/translate.c | 7 ++++++- target-moxie/translate.c | 13 +++++++++++-- target-openrisc/translate.c | 3 +++ target-ppc/translate.c | 6 +++++- target-s390x/translate.c | 3 +++ target-sh4/translate.c | 7 ++++++- target-sparc/translate.c | 7 ++++++- target-tilegx/translate.c | 3 +++ target-tricore/translate.c | 20 +++++++++++++------- target-unicore32/translate.c | 3 +++ target-xtensa/translate.c | 3 +++ tcg/tcg.h | 1 + 20 files changed, 95 insertions(+), 17 deletions(-)
target-alpha/translate.c +3 -0
@@ -2903,6 +2903,9 @@ static inline void gen_intermediate_code_internal(AlphaCPU *cpu,if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }if (in_superpage (&ctx, pc_start)) { pc_mask = (1ULL <<41 ) -1 ;
target-arm/translate-a64.c +3 -0
@@ -11072,6 +11072,9 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }gen_tb_start (tb);
target-arm/translate.c +5 -1
@@ -11258,8 +11258,12 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu, lj =-1 ; num_insns =0 ; max_insns = tb->cflags &CF_COUNT_MASK ; -if (max_insns ==0 ) +if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; + } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }gen_tb_start (tb);
target-cris/translate.c +3 -0
@@ -3155,6 +3155,9 @@ gen_intermediate_code_internal(CRISCPU *cpu, TranslationBlock *tb,if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }gen_tb_start (tb); do {
target-i386/translate.c +5 -1
@@ -7932,8 +7932,12 @@ static inline void gen_intermediate_code_internal(X86CPU *cpu, lj =-1 ; num_insns =0 ; max_insns = tb->cflags &CF_COUNT_MASK ; -if (max_insns ==0 ) +if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; + } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }gen_tb_start (tb);for (;;) {
target-lm32/translate.c +3 -0
@@ -1069,6 +1069,9 @@ void gen_intermediate_code_internal(LM32CPU *cpu,if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }gen_tb_start (tb); do {
target-m68k/translate.c +5 -1
@@ -2991,8 +2991,12 @@ gen_intermediate_code_internal(M68kCPU *cpu, TranslationBlock *tb, lj =-1 ; num_insns =0 ; max_insns = tb->cflags &CF_COUNT_MASK ; -if (max_insns ==0 ) +if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; + } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }gen_tb_start (tb); do {
target-microblaze/translate.c +5 -1
@@ -1674,8 +1674,12 @@ gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb, lj =-1 ; num_insns =0 ; max_insns = tb->cflags &CF_COUNT_MASK ; -if (max_insns ==0 ) +if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; + } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }gen_tb_start (tb); do
target-mips/translate.c +6 -1
@@ -19586,8 +19586,13 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb, MO_UNALN :MO_ALIGN ; num_insns =0 ; max_insns = tb->cflags &CF_COUNT_MASK ; -if (max_insns ==0 ) +if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; + } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + } +LOG_DISAS ("\ntb %p idx %d hflags %04x\n" , tb, ctx.mem_idx, ctx.hflags);gen_tb_start (tb);while (ctx.bstate ==BS_NONE ) {
target-moxie/translate.c +11 -2
@@ -824,7 +824,7 @@ gen_intermediate_code_internal(MoxieCPU *cpu, TranslationBlock *tb,target_ulong pc_start;int j, lj =-1 ;CPUMoxieState *env = &cpu->env; -int num_insns; +int num_insns, max_insns; pc_start = tb->pc; ctx.pc = pc_start;
@@ -834,6 +834,13 @@ gen_intermediate_code_internal(MoxieCPU *cpu, TranslationBlock *tb, ctx.singlestep_enabled =0 ; ctx.bstate =BS_NONE ; num_insns =0 ; + max_insns = tb->cflags &CF_COUNT_MASK ; +if (max_insns ==0 ) { + max_insns =CF_COUNT_MASK ; + } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }gen_tb_start (tb); do {
@@ -862,10 +869,12 @@ gen_intermediate_code_internal(MoxieCPU *cpu, TranslationBlock *tb, ctx.opcode =cpu_lduw_code (env, ctx.pc); ctx.pc +=decode_opc (cpu, &ctx); +if (num_insns >= max_insns) { +break ; + }if (cs->singlestep_enabled) {break ; } -if ((ctx.pc & (TARGET_PAGE_SIZE -1 )) ==0 ) {break ; }
target-openrisc/translate.c +3 -0
@@ -1654,6 +1654,9 @@ static inline void gen_intermediate_code_internal(OpenRISCCPU *cpu,if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }gen_tb_start (tb);
target-ppc/translate.c +5 -1
@@ -11475,8 +11475,12 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,#endif num_insns =0 ; max_insns = tb->cflags &CF_COUNT_MASK ; -if (max_insns ==0 ) +if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; + } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }gen_tb_start (tb);tcg_clear_temp_count ();
target-s390x/translate.c +3 -0
@@ -5352,6 +5352,9 @@ static inline void gen_intermediate_code_internal(S390CPU *cpu,if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }gen_tb_start (tb);
target-sh4/translate.c +6 -1
@@ -1844,8 +1844,13 @@ gen_intermediate_code_internal(SuperHCPU *cpu, TranslationBlock *tb, ii =-1 ; num_insns =0 ; max_insns = tb->cflags &CF_COUNT_MASK ; -if (max_insns ==0 ) +if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; + } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + } +gen_tb_start (tb);while (ctx.bstate ==BS_NONE && !tcg_op_buf_full ()) {if (search_pc) {
target-sparc/translate.c +6 -1
@@ -5236,8 +5236,13 @@ static inline void gen_intermediate_code_internal(SPARCCPU *cpu, num_insns =0 ; max_insns = tb->cflags &CF_COUNT_MASK ; -if (max_insns ==0 ) +if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; + } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + } +gen_tb_start (tb); do { if (spc) {
target-tilegx/translate.c +3 -0
@@ -2081,6 +2081,9 @@ static inline void gen_intermediate_code_internal(TileGXCPU *cpu,if (cs->singlestep_enabled || singlestep) { max_insns =1 ; } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }gen_tb_start (tb);while (1 ) {
target-tricore/translate.c +13 -7
@@ -8274,13 +8274,24 @@ gen_intermediate_code_internal(TriCoreCPU *cpu, struct TranslationBlock *tb,CPUTriCoreState *env = &cpu->env;DisasContext ctx;target_ulong pc_start; -int num_insns; +int num_insns, max_insns;if (search_pc) {qemu_log ("search pc %d\n" , search_pc); } num_insns =0 ; + max_insns = tb->cflags &CF_COUNT_MASK ; +if (max_insns ==0 ) { + max_insns =CF_COUNT_MASK ; + } +if (singlestep) { + max_insns =1 ; + } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + } + pc_start = tb->pc; ctx.pc = pc_start; ctx.saved_pc =-1 ;
@@ -8298,12 +8309,7 @@ gen_intermediate_code_internal(TriCoreCPU *cpu, struct TranslationBlock *tb, ctx.opcode =cpu_ldl_code (env, ctx.pc);decode_opc (env, &ctx,0 ); -if (tcg_op_buf_full ()) { -gen_save_pc (ctx.next_pc); -tcg_gen_exit_tb (0 ); -break ; - } -if (singlestep) { +if (num_insns >= max_insns ||tcg_op_buf_full ()) {gen_save_pc (ctx.next_pc);tcg_gen_exit_tb (0 );break ;
target-unicore32/translate.c +3 -0
@@ -1900,6 +1900,9 @@ static inline void gen_intermediate_code_internal(UniCore32CPU *cpu,if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + }#ifndef CONFIG_USER_ONLY if ((env->uncached_asr &ASR_M ) ==ASR_MODE_USER ) {
target-xtensa/translate.c +3 -0
@@ -3014,6 +3014,9 @@ void gen_intermediate_code_internal(XtensaCPU *cpu,if (max_insns ==0 ) { max_insns =CF_COUNT_MASK ; } +if (max_insns >TCG_MAX_INSNS ) { + max_insns =TCG_MAX_INSNS ; + } dc.config = env->config; dc.singlestep_enabled = cs->singlestep_enabled;
tcg/tcg.h +1 -0
@@ -194,6 +194,7 @@ typedef struct TCGPool {#define TCG_POOL_CHUNK_SIZE 32768#define TCG_MAX_TEMPS 512 +#define TCG_MAX_INSNS 512/* when the size of the arguments of a called function is smaller than this value, they are statically allocated in the TB stack frame */
Signature · 1 line
2.4.3
PATCH v4 19/26 tcg: Pass data argument to restore_state_to_opc
In reply to Richard HendersonThe gen_opc_* arrays are already redundant with the data stored in the insn_start arguments. Transition restore_state_to_opc to use data from the latter.
--- include/exec/exec-all.h | 2 +- target-alpha/translate.c | 5 +++-- target-arm/translate.c | 9 +++++---- target-cris/translate.c | 5 +++-- target-i386/translate.c | 26 ++++++-------------------- target-lm32/translate.c | 5 +++-- target-m68k/translate.c | 5 +++-- target-microblaze/translate.c | 5 +++-- target-mips/translate.c | 9 +++++---- target-moxie/translate.c | 5 +++-- target-openrisc/translate.c | 4 ++-- target-ppc/translate.c | 5 +++-- target-s390x/translate.c | 8 ++++---- target-sh4/translate.c | 7 ++++--- target-sparc/translate.c | 10 ++++++---- target-tilegx/translate.c | 5 +++-- target-tricore/translate.c | 5 +++-- target-unicore32/translate.c | 5 +++-- target-xtensa/translate.c | 5 +++-- tcg/tcg.c | 11 ++++++++++- tcg/tcg.h | 2 ++ translate-all.c | 2 +- 22 files changed, 79 insertions(+), 66 deletions(-)
include/exec/exec-all.h +1 -1
@@ -75,7 +75,7 @@ typedef struct TranslationBlock TranslationBlock;void gen_intermediate_code (CPUArchState *env,struct TranslationBlock *tb);void gen_intermediate_code_pc (CPUArchState *env,struct TranslationBlock *tb);void restore_state_to_opc (CPUArchState *env,struct TranslationBlock *tb, -int pc_pos); +target_ulong *data);void cpu_gen_init (void );bool cpu_restore_state (CPUState *cpu,uintptr_t searched_pc);
target-alpha/translate.c +3 -2
@@ -3023,7 +3023,8 @@ void gen_intermediate_code_pc (CPUAlphaState *env, struct TranslationBlock *tb)gen_intermediate_code_internal (alpha_env_get_cpu (env), tb, true); } -void restore_state_to_opc (CPUAlphaState *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUAlphaState *env,TranslationBlock *tb, +target_ulong *data) { - env->pc = tcg_ctx.gen_opc_pc[pc_pos]; + env->pc = data[0 ]; }
target-arm/translate.c +5 -4
@@ -11612,13 +11612,14 @@ void arm_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, } } -void restore_state_to_opc (CPUARMState *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUARMState *env,TranslationBlock *tb, +target_ulong *data) {if (is_a64 (env)) { - env->pc = tcg_ctx.gen_opc_pc[pc_pos]; + env->pc = data[0 ]; env->condexec_bits =0 ; }else { - env->regs[15 ] = tcg_ctx.gen_opc_pc[pc_pos]; - env->condexec_bits = gen_opc_condexec_bits[pc_pos]; + env->regs[15 ] = data[0 ]; + env->condexec_bits = data[1 ]; } }
target-cris/translate.c +3 -2
@@ -3433,7 +3433,8 @@ void cris_initialize_tcg(void) } } -void restore_state_to_opc (CPUCRISState *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUCRISState *env,TranslationBlock *tb, +target_ulong *data) { - env->pc = tcg_ctx.gen_opc_pc[pc_pos]; + env->pc = data[0 ]; }
target-i386/translate.c +6 -20
@@ -8055,26 +8055,12 @@ void gen_intermediate_code_pc(CPUX86State *env, TranslationBlock *tb)gen_intermediate_code_internal (x86_env_get_cpu (env), tb, true); } -void restore_state_to_opc (CPUX86State *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUX86State *env,TranslationBlock *tb, +target_ulong *data) { -int cc_op; -#ifdef DEBUG_DISAS -if (qemu_loglevel_mask (CPU_LOG_TB_OP )) { -int i; -qemu_log ("RESTORE:\n" ); -for (i =0 ;i <= pc_pos; i++) { -if (tcg_ctx.gen_opc_instr_start[i]) { -qemu_log ("0x%04x: " TARGET_FMT_lx"\n" , i, - tcg_ctx.gen_opc_pc[i]); - } - } -qemu_log ("pc_pos=0x%x eip=" TARGET_FMT_lx" cs_base=%x\n" , - pc_pos, tcg_ctx.gen_opc_pc[pc_pos] - tb->cs_base, - (uint32_t )tb->cs_base); - } -#endif - env->eip = tcg_ctx.gen_opc_pc[pc_pos] - tb->cs_base; - cc_op = gen_opc_cc_op[pc_pos]; -if (cc_op !=CC_OP_DYNAMIC ) +int cc_op = data[1 ]; + env->eip = data[0 ] - tb->cs_base; +if (cc_op !=CC_OP_DYNAMIC ) { env->cc_op = cc_op; + } }
target-lm32/translate.c +3 -2
@@ -1207,9 +1207,10 @@ void lm32_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,cpu_fprintf (f,"\n\n" ); } -void restore_state_to_opc (CPULM32State *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPULM32State *env,TranslationBlock *tb, +target_ulong *data) { - env->pc = tcg_ctx.gen_opc_pc[pc_pos]; + env->pc = data[0 ]; }void lm32_translate_init (void )
target-m68k/translate.c +3 -2
@@ -3118,7 +3118,8 @@ void m68k_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,cpu_fprintf (f,"FPRESULT = %12g\n" , *(double *)&env->fp_result); } -void restore_state_to_opc (CPUM68KState *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUM68KState *env,TranslationBlock *tb, +target_ulong *data) { - env->pc = tcg_ctx.gen_opc_pc[pc_pos]; + env->pc = data[0 ]; }
target-microblaze/translate.c +3 -2
@@ -1928,7 +1928,8 @@ void mb_tcg_init(void) } } -void restore_state_to_opc (CPUMBState *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUMBState *env,TranslationBlock *tb, +target_ulong *data) { - env->sregs[SR_PC ] = tcg_ctx.gen_opc_pc[pc_pos]; + env->sregs[SR_PC ] = data[0 ]; }
target-mips/translate.c +5 -4
@@ -20061,18 +20061,19 @@ void cpu_state_reset(CPUMIPSState *env) } } -void restore_state_to_opc (CPUMIPSState *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUMIPSState *env,TranslationBlock *tb, +target_ulong *data) { - env->active_tc.PC = tcg_ctx.gen_opc_pc[pc_pos]; + env->active_tc.PC = data[0 ]; env->hflags &= ~MIPS_HFLAG_BMASK ; - env->hflags |= gen_opc_hflags[pc_pos]; + env->hflags |= data[1 ];switch (env->hflags &MIPS_HFLAG_BMASK_BASE ) {case MIPS_HFLAG_BR :break ;case MIPS_HFLAG_BC :case MIPS_HFLAG_BL :case MIPS_HFLAG_B : - env->btarget = gen_opc_btarget[pc_pos]; + env->btarget = data[2 ];break ; } }
target-moxie/translate.c +3 -2
@@ -922,7 +922,8 @@ void gen_intermediate_code_pc(CPUMoxieState *env, struct TranslationBlock *tb)gen_intermediate_code_internal (moxie_env_get_cpu (env), tb, true); } -void restore_state_to_opc (CPUMoxieState *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUMoxieState *env,TranslationBlock *tb, +target_ulong *data) { - env->pc = tcg_ctx.gen_opc_pc[pc_pos]; + env->pc = data[0 ]; }
target-openrisc/translate.c +2 -2
@@ -1794,7 +1794,7 @@ void openrisc_cpu_dump_state(CPUState *cs, FILE *f, }void restore_state_to_opc (CPUOpenRISCState *env,TranslationBlock *tb, -int pc_pos) +target_ulong *data) { - env->pc = tcg_ctx.gen_opc_pc[pc_pos]; + env->pc = data[0 ]; }
target-ppc/translate.c +3 -2
@@ -11629,7 +11629,8 @@ void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb)gen_intermediate_code_internal (ppc_env_get_cpu (env), tb, true); } -void restore_state_to_opc (CPUPPCState *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUPPCState *env,TranslationBlock *tb, +target_ulong *data) { - env->nip = tcg_ctx.gen_opc_pc[pc_pos]; + env->nip = data[0 ]; }
target-s390x/translate.c +4 -4
@@ -5460,11 +5460,11 @@ void gen_intermediate_code_pc (CPUS390XState *env, struct TranslationBlock *tb)gen_intermediate_code_internal (s390_env_get_cpu (env), tb, true); } -void restore_state_to_opc (CPUS390XState *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUS390XState *env,TranslationBlock *tb, +target_ulong *data) { -int cc_op; - env->psw.addr = tcg_ctx.gen_opc_pc[pc_pos]; - cc_op = gen_opc_cc_op[pc_pos]; +int cc_op = data[1 ]; + env->psw.addr = data[0 ];if ((cc_op !=CC_OP_DYNAMIC ) && (cc_op !=CC_OP_STATIC )) { env->cc_op = cc_op; }
target-sh4/translate.c +4 -3
@@ -1950,8 +1950,9 @@ void gen_intermediate_code_pc(CPUSH4State * env, struct TranslationBlock *tb)gen_intermediate_code_internal (sh_env_get_cpu (env), tb, true); } -void restore_state_to_opc (CPUSH4State *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUSH4State *env,TranslationBlock *tb, +target_ulong *data) { - env->pc = tcg_ctx.gen_opc_pc[pc_pos]; - env->flags = gen_opc_hflags[pc_pos]; + env->pc = data[0 ]; + env->flags = data[1 ]; }
target-sparc/translate.c +6 -4
@@ -5459,11 +5459,13 @@ void gen_intermediate_code_init(CPUSPARCState *env) } } -void restore_state_to_opc (CPUSPARCState *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUSPARCState *env,TranslationBlock *tb, +target_ulong *data) { -target_ulong pc, npc; - env->pc = pc = tcg_ctx.gen_opc_pc[pc_pos]; - npc = gen_opc_npc[pc_pos]; +target_ulong pc = data[0 ]; +target_ulong npc = data[1 ]; + + env->pc = pc;if (npc ==DYNAMIC_PC ) {/* dynamic NPC: already stored */ }else if (npc &JUMP_PC ) {
target-tilegx/translate.c +3 -2
@@ -2144,9 +2144,10 @@ void gen_intermediate_code_pc(CPUTLGState *env, struct TranslationBlock *tb)gen_intermediate_code_internal (tilegx_env_get_cpu (env), tb, true); } -void restore_state_to_opc (CPUTLGState *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUTLGState *env,TranslationBlock *tb, +target_ulong *data) { - env->pc = tcg_ctx.gen_opc_pc[pc_pos]; + env->pc = data[0 ]; }void tilegx_tcg_init (void )
target-tricore/translate.c +3 -2
@@ -8350,9 +8350,10 @@ gen_intermediate_code_pc(CPUTriCoreState *env, struct TranslationBlock *tb) }void -restore_state_to_opc (CPUTriCoreState *env,TranslationBlock *tb,int pc_pos) +restore_state_to_opc (CPUTriCoreState *env,TranslationBlock *tb, +target_ulong *data) { - env->PC = tcg_ctx.gen_opc_pc[pc_pos]; + env->PC = data[0 ]; }/* *
target-unicore32/translate.c +3 -2
@@ -2129,7 +2129,8 @@ void uc32_cpu_dump_state(CPUState *cs, FILE *f,cpu_dump_state_ucf64 (env, f, cpu_fprintf, flags); } -void restore_state_to_opc (CPUUniCore32State *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUUniCore32State *env,TranslationBlock *tb, +target_ulong *data) { - env->regs[31 ] = tcg_ctx.gen_opc_pc[pc_pos]; + env->regs[31 ] = data[0 ]; }
target-xtensa/translate.c +3 -2
@@ -3202,7 +3202,8 @@ void xtensa_cpu_dump_state(CPUState *cs, FILE *f, } } -void restore_state_to_opc (CPUXtensaState *env,TranslationBlock *tb,int pc_pos) +void restore_state_to_opc (CPUXtensaState *env,TranslationBlock *tb, +target_ulong *data) { - env->pc = tcg_ctx.gen_opc_pc[pc_pos]; + env->pc = data[0 ]; }
tcg/tcg.c +10 -1
@@ -2294,7 +2294,7 @@ static inline int tcg_gen_code_common(TCGContext *s,tcg_insn_unit *gen_code_buf, long search_pc) { - int oi, oi_next; + int i, oi, oi_next; #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) {
@@ -2361,6 +2361,15 @@ static inline int tcg_gen_code_common(TCGContext *s,tcg_reg_alloc_movi (s, args, dead_args, sync_args);break ;case INDEX_op_insn_start: +for (i =0 ; i <TARGET_INSN_START_WORDS ; ++i) { +target_ulong a; +#if TARGET_LONG_BITS >TCG_TARGET_REG_BITS + a = ((target_ulong )args[i *2 +1 ] <<32 ) | args[i *2 ]; +#else + a = args[i]; +#endif + s->gen_opc_data[i] = a; + }break ;case INDEX_op_discard:temp_dead (s, args[0 ]);
tcg/tcg.h +2 -0
@@ -580,6 +580,8 @@ struct TCGContext {target_ulong gen_opc_pc[OPC_BUF_SIZE ];uint16_t gen_opc_icount[OPC_BUF_SIZE ];uint8_t gen_opc_instr_start[OPC_BUF_SIZE ]; + +target_ulong gen_opc_data[TARGET_INSN_START_WORDS ]; };extern TCGContext tcg_ctx;
translate-all.c +1 -1
@@ -218,7 +218,7 @@ static int cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, } cpu->icount_decr.u16.low -= s->gen_opc_icount[j]; -restore_state_to_opc (env, tb, j); +restore_state_to_opc (env, tb, s->gen_opc_data);#ifdef CONFIG_PROFILER s->restore_time +=profile_getclock () - ti;
Signature · 1 line
2.4.3
PATCH v4 20/26 tcg: Save insn data and use it in cpu_restore_state_from_tb
In reply to Richard HendersonWe can now restore state without retranslation.
--- include/exec/exec-all.h | 1 + tcg/tcg.c | 40 ++++++++----- tcg/tcg.h | 4 +- translate-all.c | 150 +++++++++++++++++++++++++++++++++++------------- 4 files changed, 140 insertions(+), 55 deletions(-)
include/exec/exec-all.h +1 -0
@@ -199,6 +199,7 @@ struct TranslationBlock {#define CF_USE_ICOUNT 0x20000void *tc_ptr;/* pointer to the translated code */ +uint8_t *tc_search;/* pointer to search data */ /* next matching tb for physical address. */ struct TranslationBlock *phys_hash_next;/* original tb when cflags has CF_NOCACHE */
tcg/tcg.c +26 -14
@@ -2294,7 +2294,7 @@ static inline int tcg_gen_code_common(TCGContext *s,tcg_insn_unit *gen_code_buf, long search_pc) { - int i, oi, oi_next; + int i, oi, oi_next, num_insns; #ifdef DEBUG_DISAS if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) {
@@ -2338,6 +2338,7 @@ static inline int tcg_gen_code_common(TCGContext *s,tcg_out_tb_init (s); + num_insns =-1 ;for (oi = s->gen_first_op_idx; oi >=0 ; oi = oi_next) {TCGOp *const op = &s->gen_op_buf[oi];TCGArg *const args = &s->gen_opparam_buf[op->args];
@@ -2361,6 +2362,10 @@ static inline int tcg_gen_code_common(TCGContext *s,tcg_reg_alloc_movi (s, args, dead_args, sync_args);break ;case INDEX_op_insn_start: +if (num_insns >=0 ) { + s->gen_insn_end_off[num_insns] =tcg_current_code_size (s); + } + num_insns++;for (i =0 ; i <TARGET_INSN_START_WORDS ; ++i) {target_ulong a;#if TARGET_LONG_BITS >TCG_TARGET_REG_BITS
@@ -2368,7 +2373,7 @@ static inline int tcg_gen_code_common(TCGContext *s,#else a = args[i];#endif - s->gen_opc_data[i] = a; + s->gen_insn_data[num_insns][i] = a; }break ;case INDEX_op_discard:
@@ -2400,6 +2405,8 @@ static inline int tcg_gen_code_common(TCGContext *s,check_regs (s);#endif } +tcg_debug_assert (num_insns >=0 ); + s->gen_insn_end_off[num_insns] =tcg_current_code_size (s);/* Generate TB finalization at the end of block */ tcg_out_tb_finalize (s);
@@ -2448,24 +2455,26 @@ int tcg_gen_code_search_pc(TCGContext *s, tcg_insn_unit *gen_code_buf,void tcg_dump_info (FILE *f,fprintf_function cpu_fprintf) {TCGContext *s = &tcg_ctx; -int64_t tot; +int64_t tb_count = s->tb_count; +int64_t tb_div_count = tb_count ? tb_count :1 ; +int64_t tot = s->interm_time + s->code_time; - tot = s->interm_time + s->code_time;cpu_fprintf (f,"JIT cycles %" PRId64" (%0.3f s at 2.4 GHz)\n" , tot, tot /2.4e9 );cpu_fprintf (f,"translated TBs %" PRId64" (aborted=%" PRId64" %0.1f%%)\n" , - s->tb_count, - s->tb_count1 - s->tb_count, - s->tb_count1 ? (double )(s->tb_count1 - s->tb_count) / s->tb_count1 *100.0 :0 ); + tb_count, s->tb_count1 - tb_count, + (double )(s->tb_count1 - s->tb_count) + / (s->tb_count1 ? s->tb_count1 :1 ) *100.0 );cpu_fprintf (f,"avg ops/TB %0.1f max=%d\n" , - s->tb_count ? (double )s->op_count / s->tb_count :0 , s->op_count_max); + (double )s->op_count / tb_div_count, s->op_count_max);cpu_fprintf (f,"deleted ops/TB %0.2f\n" , - s->tb_count ? - (double )s->del_op_count / s->tb_count :0 ); + (double )s->del_op_count / tb_div_count);cpu_fprintf (f,"avg temps/TB %0.2f max=%d\n" , - s->tb_count ? - (double )s->temp_count / s->tb_count :0 , - s->temp_count_max); + (double )s->temp_count / tb_div_count, s->temp_count_max); +cpu_fprintf (f,"avg host code/TB %0.1f\n" , + (double )s->code_out_len / tb_div_count); +cpu_fprintf (f,"avg search data/TB %0.1f\n" , + (double )s->search_out_len / tb_div_count);cpu_fprintf (f,"cycles/op %0.1f\n" , s->op_count ? (double )tot / s->op_count :0 );
@@ -2473,8 +2482,11 @@ void tcg_dump_info(FILE *f, fprintf_function cpu_fprintf) s->code_in_len ? (double)tot / s->code_in_len : 0);cpu_fprintf (f,"cycles/out byte %0.1f\n" , s->code_out_len ? (double )tot / s->code_out_len :0 ); -if (tot ==0 ) +cpu_fprintf (f,"cycles/search byte %0.1f\n" , + s->search_out_len ? (double )tot / s->search_out_len :0 ); +if (tot ==0 ) { tot =1 ; + }cpu_fprintf (f," gen_interm time %0.1f%%\n" , (double )s->interm_time / tot *100.0 ); cpu_fprintf(f, " gen_code time %0.1f%%\n",
tcg/tcg.h +3 -1
@@ -532,6 +532,7 @@ struct TCGContext {int64_t del_op_count;int64_t code_in_len;int64_t code_out_len; +int64_t search_out_len;int64_t interm_time;int64_t code_time;int64_t la_time;
@@ -581,7 +582,8 @@ struct TCGContext {uint16_t gen_opc_icount[OPC_BUF_SIZE ];uint8_t gen_opc_instr_start[OPC_BUF_SIZE ]; -target_ulong gen_opc_data[TARGET_INSN_START_WORDS ]; +uint16_t gen_insn_end_off[TCG_MAX_INSNS ]; +target_ulong gen_insn_data[TCG_MAX_INSNS ][TARGET_INSN_START_WORDS ]; };extern TCGContext tcg_ctx;
translate-all.c +110 -40
197 lines not on this page · raw message
Signature · 1 line
2.4.3
PATCH v4 22/26 tcg: Remove tcg_gen_code_search_pc
In reply to Richard HendersonIt's no longer used, so tidy up everything reached by it.
--- tcg/tcg.c | 59 +++++++++++++++++++---------------------------------------- tcg/tcg.h | 2 -- 2 files changed, 19 insertions(+), 42 deletions(-)
tcg/tcg.c +19 -40
@@ -2290,12 +2290,28 @@ void tcg_dump_op_count(FILE *f, fprintf_function cpu_fprintf)#endif -static inline int tcg_gen_code_common (TCGContext *s, -tcg_insn_unit *gen_code_buf, -long search_pc) +int tcg_gen_code (TCGContext *s,tcg_insn_unit *gen_code_buf) {int i, oi, oi_next, num_insns; +#ifdef CONFIG_PROFILER + { +int n; + + n = s->gen_last_op_idx +1 ; + s->op_count += n; +if (n > s->op_count_max) { + s->op_count_max = n; + } + + n = s->nb_temps; + s->temp_count += n; +if (n > s->temp_count_max) { + s->temp_count_max = n; + } + } +#endif +#ifdef DEBUG_DISAS if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP ))) {qemu_log ("OP:\n" );
@@ -2398,9 +2414,6 @@ static inline int tcg_gen_code_common(TCGContext *s,tcg_reg_alloc_op (s, def, opc, args, dead_args, sync_args);break ; } -if (search_pc >=0 && search_pc <tcg_current_code_size (s)) { -return oi; - }#ifndef NDEBUG check_regs (s);#endif
@@ -2410,30 +2423,6 @@ static inline int tcg_gen_code_common(TCGContext *s,/* Generate TB finalization at the end of block */ tcg_out_tb_finalize (s); -return -1 ; -} - -int tcg_gen_code (TCGContext *s,tcg_insn_unit *gen_code_buf) -{ -#ifdef CONFIG_PROFILER - { -int n; - - n = s->gen_last_op_idx +1 ; - s->op_count += n; -if (n > s->op_count_max) { - s->op_count_max = n; - } - - n = s->nb_temps; - s->temp_count += n; -if (n > s->temp_count_max) { - s->temp_count_max = n; - } - } -#endif - -tcg_gen_code_common (s, gen_code_buf,-1 );/* flush instruction cache */ flush_icache_range ((uintptr_t )s->code_buf, (uintptr_t )s->code_ptr);
@@ -2441,16 +2430,6 @@ int tcg_gen_code(TCGContext *s, tcg_insn_unit *gen_code_buf)return tcg_current_code_size (s); } -/* Return the index of the micro operation such as the pc after is < -offset bytes from the start of the TB. The contents of gen_code_buf must -not be changed, though writing the same values is ok. -Return -1 if not found. */ -int tcg_gen_code_search_pc (TCGContext *s,tcg_insn_unit *gen_code_buf, -long offset) -{ -return tcg_gen_code_common (s, gen_code_buf, offset); -} -#ifdef CONFIG_PROFILER void tcg_dump_info (FILE *f,fprintf_function cpu_fprintf) {
tcg/tcg.h +0 -2
@@ -626,8 +626,6 @@ void tcg_prologue_init(TCGContext *s);void tcg_func_start (TCGContext *s);int tcg_gen_code (TCGContext *s,tcg_insn_unit *gen_code_buf); -int tcg_gen_code_search_pc (TCGContext *s,tcg_insn_unit *gen_code_buf, -long offset);void tcg_set_frame (TCGContext *s,int reg,intptr_t start,intptr_t size);
Signature · 1 line
2.4.3
PATCH v4 21/26 tcg: Remove gen_intermediate_code_pc
In reply to Richard HendersonIt is no longer used, so tidy up everything reached by it. This includes the gen_opc_* arrays, the search_pc parameter and the inline gen_intermediate_code_internal functions.
--- include/exec/exec-all.h | 1 - target-alpha/translate.c | 41 ++++---------------------------- target-arm/translate-a64.c | 30 +++--------------------- target-arm/translate.c | 54 ++++++++----------------------------------- target-arm/translate.h | 8 ++----- target-cris/translate.c | 50 +++++---------------------------------- target-i386/translate.c | 49 ++++----------------------------------- target-lm32/translate.c | 42 ++++----------------------------- target-m68k/translate.c | 43 ++++------------------------------ target-microblaze/translate.c | 40 ++++---------------------------- target-mips/translate.c | 48 ++++---------------------------------- target-moxie/translate.c | 41 ++++---------------------------- target-openrisc/translate.c | 42 ++++----------------------------- target-ppc/translate.c | 40 ++++---------------------------- target-s390x/translate.c | 44 ++++------------------------------- target-sh4/translate.c | 43 ++++------------------------------ target-sparc/translate.c | 51 ++++------------------------------------ target-tilegx/translate.c | 41 ++++---------------------------- target-tricore/translate.c | 31 ++++--------------------- target-unicore32/translate.c | 44 ++++------------------------------- target-xtensa/translate.c | 39 ++++--------------------------- tcg/tcg.h | 4 ---- 22 files changed, 90 insertions(+), 736 deletions(-)
include/exec/exec-all.h +0 -1
@@ -73,7 +73,6 @@ typedef struct TranslationBlock TranslationBlock;#include "qemu/log.h" void gen_intermediate_code (CPUArchState *env,struct TranslationBlock *tb); -void gen_intermediate_code_pc (CPUArchState *env,struct TranslationBlock *tb);void restore_state_to_opc (CPUArchState *env,struct TranslationBlock *tb,target_ulong *data);
target-alpha/translate.c +4 -37
71 lines not on this page · raw message
target-arm/translate-a64.c +3 -27
@@ -11000,14 +11000,11 @@ static void disas_a64_insn(CPUARMState *env, DisasContext *s)free_tmp_a64 (s); } -void gen_intermediate_code_internal_a64 (ARMCPU *cpu, -TranslationBlock *tb, -bool search_pc) +void gen_intermediate_code_a64 (ARMCPU *cpu,TranslationBlock *tb) {CPUState *cs =CPU (cpu);CPUARMState *env = &cpu->env;DisasContext dc1, *dc = &dc1; -int j, lj;target_ulong pc_start;target_ulong next_page_start;int num_insns;
@@ -11066,7 +11063,6 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,init_tmp_a64_array (dc); next_page_start = (pc_start &TARGET_PAGE_MASK ) +TARGET_PAGE_SIZE ; - lj =-1 ; num_insns =0 ; max_insns = tb->cflags &CF_COUNT_MASK ;if (max_insns ==0 ) {
@@ -11081,18 +11077,6 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,tcg_clear_temp_count (); do { - if (search_pc) { - j = tcg_op_buf_count(); - if (lj < j) { - lj++; - while (lj < j) { - tcg_ctx.gen_opc_instr_start[lj++] = 0; - } - } - tcg_ctx.gen_opc_pc[lj] = dc->pc; - tcg_ctx.gen_opc_instr_start[lj] = 1; - tcg_ctx.gen_opc_icount[lj] = num_insns; - } tcg_gen_insn_start(dc->pc, 0); num_insns++;
@@ -11221,14 +11205,6 @@ done_generating: qemu_log("\n"); }#endif -if (search_pc) { - j =tcg_op_buf_count (); - lj++; -while (lj <= j) { - tcg_ctx.gen_opc_instr_start[lj++] =0 ; - } - }else { - tb->size = dc->pc - pc_start; - tb->icount = num_insns; - } + tb->size = dc->pc - pc_start; + tb->icount = num_insns; }
target-arm/translate.c +9 -45
99 lines not on this page · raw message
target-arm/translate.h +2 -6
@@ -122,9 +122,7 @@ static inline int default_exception_el(DisasContext *s)#ifdef TARGET_AARCH64 void a64_translate_init (void ); -void gen_intermediate_code_internal_a64 (ARMCPU *cpu, -TranslationBlock *tb, -bool search_pc); +void gen_intermediate_code_a64 (ARMCPU *cpu,TranslationBlock *tb);void gen_a64_set_pc_im (uint64_t val);void aarch64_cpu_dump_state (CPUState *cs,FILE *f,fprintf_function cpu_fprintf,int flags);
@@ -133,9 +131,7 @@ static inline void a64_translate_init(void) { } -static inline void gen_intermediate_code_internal_a64 (ARMCPU *cpu, -TranslationBlock *tb, -bool search_pc) +static inline void gen_intermediate_code_a64 (ARMCPU *cpu,TranslationBlock *tb) { }
target-cris/translate.c +6 -44
95 lines not on this page · raw message
target-i386/translate.c +5 -44
89 lines not on this page · raw message
target-lm32/translate.c +4 -38
76 lines not on this page · raw message
target-m68k/translate.c +4 -39
70 lines not on this page · raw message
target-microblaze/translate.c +4 -36
@@ -1627,14 +1627,11 @@ static inline void decode(DisasContext *dc, uint32_t ir) }/* generate intermediate code for basic block 'tb'. */ -static inline void -gen_intermediate_code_internal (MicroBlazeCPU *cpu,TranslationBlock *tb, -bool search_pc) +void gen_intermediate_code (CPUMBState *env,struct TranslationBlock *tb) { +MicroBlazeCPU *cpu =mb_env_get_cpu (env);CPUState *cs =CPU (cpu); -CPUMBState *env = &cpu->env;uint32_t pc_start; -int j, lj;struct DisasContext ctx;struct DisasContext *dc = &ctx;uint32_t next_page_start, org_flags;
@@ -1671,7 +1668,6 @@ gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb, } next_page_start = (pc_start &TARGET_PAGE_MASK ) +TARGET_PAGE_SIZE ; - lj =-1 ; num_insns =0 ; max_insns = tb->cflags &CF_COUNT_MASK ;if (max_insns ==0 ) {
@@ -1684,17 +1680,6 @@ gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb,gen_tb_start (tb); do { - if (search_pc) { - j = tcg_op_buf_count(); - if (lj < j) { - lj++; - while (lj < j) - tcg_ctx.gen_opc_instr_start[lj++] = 0; - } - tcg_ctx.gen_opc_pc[lj] = dc->pc; - tcg_ctx.gen_opc_instr_start[lj] = 1; - tcg_ctx.gen_opc_icount[lj] = num_insns; - } tcg_gen_insn_start(dc->pc); num_insns++;
@@ -1813,15 +1798,8 @@ gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb, }gen_tb_end (tb, num_insns); -if (search_pc) { - j =tcg_op_buf_count (); - lj++; -while (lj <= j) - tcg_ctx.gen_opc_instr_start[lj++] =0 ; - }else { - tb->size = dc->pc - pc_start; - tb->icount = num_insns; - } + tb->size = dc->pc - pc_start; + tb->icount = num_insns;#ifdef DEBUG_DISAS #if !SIM_COMPAT
@@ -1838,16 +1816,6 @@ gen_intermediate_code_internal(MicroBlazeCPU *cpu, TranslationBlock *tb,assert (!dc->abort_at_next_insn); } -void gen_intermediate_code (CPUMBState *env,struct TranslationBlock *tb) -{ -gen_intermediate_code_internal (mb_env_get_cpu (env), tb, false); -} - -void gen_intermediate_code_pc (CPUMBState *env,struct TranslationBlock *tb) -{ -gen_intermediate_code_internal (mb_env_get_cpu (env), tb, true); -} -void mb_cpu_dump_state (CPUState *cs,FILE *f,fprintf_function cpu_fprintf,int flags) {
target-mips/translate.c +5 -43
88 lines not on this page · raw message
target-moxie/translate.c +4 -37
63 lines not on this page · raw message
target-openrisc/translate.c +4 -38
76 lines not on this page · raw message
target-ppc/translate.c +5 -35
@@ -11409,16 +11409,13 @@ void ppc_cpu_dump_statistics(CPUState *cs, FILE*f, }/*****************************************************************************/ -static inline void gen_intermediate_code_internal (PowerPCCPU *cpu, -TranslationBlock *tb, -bool search_pc) +void gen_intermediate_code (CPUPPCState *env,struct TranslationBlock *tb) { +PowerPCCPU *cpu =ppc_env_get_cpu (env);CPUState *cs =CPU (cpu); -CPUPPCState *env = &cpu->env;DisasContext ctx, *ctxp = &ctx;opc_handler_t **table, *handler;target_ulong pc_start; -int j, lj =-1 ;int num_insns;int max_insns;
@@ -11486,17 +11483,6 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,tcg_clear_temp_count ();/* Set env in case of segfault during code fetch */ while (ctx.exception ==POWERPC_EXCP_NONE && !tcg_op_buf_full ()) { -if (unlikely (search_pc)) { - j =tcg_op_buf_count (); -if (lj < j) { - lj++; -while (lj < j) - tcg_ctx.gen_opc_instr_start[lj++] =0 ; - } - tcg_ctx.gen_opc_pc[lj] = ctx.nip; - tcg_ctx.gen_opc_instr_start[lj] =1 ; - tcg_ctx.gen_opc_icount[lj] = num_insns; - }tcg_gen_insn_start (ctx.nip); num_insns++;
@@ -11598,15 +11584,9 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu, }gen_tb_end (tb, num_insns); -if (unlikely (search_pc)) { - j =tcg_op_buf_count (); - lj++; -while (lj <= j) - tcg_ctx.gen_opc_instr_start[lj++] =0 ; - }else { - tb->size = ctx.nip - pc_start; - tb->icount = num_insns; - } + tb->size = ctx.nip - pc_start; + tb->icount = num_insns; +#if defined(DEBUG_DISAS )if (qemu_loglevel_mask (CPU_LOG_TB_IN_ASM )) {int flags;
@@ -11619,16 +11599,6 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu,#endif } -void gen_intermediate_code (CPUPPCState *env,struct TranslationBlock *tb) -{ -gen_intermediate_code_internal (ppc_env_get_cpu (env), tb, false); -} - -void gen_intermediate_code_pc (CPUPPCState *env,struct TranslationBlock *tb) -{ -gen_intermediate_code_internal (ppc_env_get_cpu (env), tb, true); -} -void restore_state_to_opc (CPUPPCState *env,TranslationBlock *tb,target_ulong *data) {
target-s390x/translate.c +4 -40
79 lines not on this page · raw message
target-sh4/translate.c +4 -39
83 lines not on this page · raw message
target-sparc/translate.c +5 -46
85 lines not on this page · raw message
target-tilegx/translate.c +4 -37
69 lines not on this page · raw message
target-tricore/translate.c +5 -26
@@ -8266,20 +8266,14 @@ static void decode_opc(CPUTriCoreState *env, DisasContext *ctx, int *is_branch) } } -static inline void -gen_intermediate_code_internal (TriCoreCPU *cpu,struct TranslationBlock *tb, -int search_pc) +void gen_intermediate_code (CPUTriCoreState *env,struct TranslationBlock *tb) { +TriCoreCPU *cpu =tricore_env_get_cpu (env);CPUState *cs =CPU (cpu); -CPUTriCoreState *env = &cpu->env;DisasContext ctx;target_ulong pc_start;int num_insns, max_insns; -if (search_pc) { -qemu_log ("search pc %d\n" , search_pc); - } - num_insns =0 ; max_insns = tb->cflags &CF_COUNT_MASK ;if (max_insns ==0 ) {
@@ -8318,12 +8312,9 @@ gen_intermediate_code_internal(TriCoreCPU *cpu, struct TranslationBlock *tb, }gen_tb_end (tb, num_insns); -if (search_pc) { -printf ("done_generating search pc\n" ); - }else { - tb->size = ctx.pc - pc_start; - tb->icount = num_insns; - } + tb->size = ctx.pc - pc_start; + tb->icount = num_insns; +if (tcg_check_temp_count ()) {printf ("LEAK at %08x\n" , env->PC); }
@@ -8338,18 +8329,6 @@ gen_intermediate_code_internal(TriCoreCPU *cpu, struct TranslationBlock *tb, }void -gen_intermediate_code (CPUTriCoreState *env,struct TranslationBlock *tb) -{ -gen_intermediate_code_internal (tricore_env_get_cpu (env), tb, false); -} - -void -gen_intermediate_code_pc (CPUTriCoreState *env,struct TranslationBlock *tb) -{ -gen_intermediate_code_internal (tricore_env_get_cpu (env), tb, true); -} - -void restore_state_to_opc (CPUTriCoreState *env,TranslationBlock *tb,target_ulong *data) {
target-unicore32/translate.c +5 -39
71 lines not on this page · raw message
target-xtensa/translate.c +4 -35
@@ -2997,15 +2997,12 @@ static void gen_ibreak_check(CPUXtensaState *env, DisasContext *dc) } } -static inline -void gen_intermediate_code_internal (XtensaCPU *cpu, -TranslationBlock *tb,bool search_pc) +void gen_intermediate_code (CPUXtensaState *env,TranslationBlock *tb) { +XtensaCPU *cpu =xtensa_env_get_cpu (env);CPUState *cs =CPU (cpu); -CPUXtensaState *env = &cpu->env;DisasContext dc;int insn_count =0 ; -int j, lj =-1 ;int max_insns = tb->cflags &CF_COUNT_MASK ;uint32_t pc_start = tb->pc; uint32_t next_page_start =
@@ -3049,18 +3046,6 @@ void gen_intermediate_code_internal(XtensaCPU *cpu, } do { - if (search_pc) { - j = tcg_op_buf_count(); - if (lj < j) { - lj++; - while (lj < j) { - tcg_ctx.gen_opc_instr_start[lj++] = 0; - } - } - tcg_ctx.gen_opc_pc[lj] = dc.pc; - tcg_ctx.gen_opc_instr_start[lj] = 1; - tcg_ctx.gen_opc_icount[lj] = insn_count; - } tcg_gen_insn_start(dc.pc); ++insn_count;
@@ -3131,24 +3116,8 @@ void gen_intermediate_code_internal(XtensaCPU *cpu,qemu_log ("\n" ); }#endif -if (search_pc) { - j =tcg_op_buf_count (); -memset (tcg_ctx.gen_opc_instr_start + lj +1 ,0 , - (j - lj) *sizeof (tcg_ctx.gen_opc_instr_start[0 ])); - }else { - tb->size = dc.pc - pc_start; - tb->icount = insn_count; - } -} - -void gen_intermediate_code (CPUXtensaState *env,TranslationBlock *tb) -{ -gen_intermediate_code_internal (xtensa_env_get_cpu (env), tb, false); -} - -void gen_intermediate_code_pc (CPUXtensaState *env,TranslationBlock *tb) -{ -gen_intermediate_code_internal (xtensa_env_get_cpu (env), tb, true); + tb->size = dc.pc - pc_start; + tb->icount = insn_count; } void xtensa_cpu_dump_state(CPUState *cs, FILE *f,
tcg/tcg.h +0 -4
@@ -578,10 +578,6 @@ struct TCGContext {TCGOp gen_op_buf[OPC_BUF_SIZE ];TCGArg gen_opparam_buf[OPPARAM_BUF_SIZE ]; -target_ulong gen_opc_pc[OPC_BUF_SIZE ]; -uint16_t gen_opc_icount[OPC_BUF_SIZE ]; -uint8_t gen_opc_instr_start[OPC_BUF_SIZE ]; -uint16_t gen_insn_end_off[TCG_MAX_INSNS ];target_ulong gen_insn_data[TCG_MAX_INSNS ][TARGET_INSN_START_WORDS ]; };
Signature · 1 line
2.4.3
PATCH v4 23/26 tcg: Emit prologue to the beginning of code_gen_buffer
In reply to Richard HendersonBy putting the prologue at the end, we risk overwriting the prologue should our estimate of maximum TB size. Given the two different placements of the call to tcg_prologue_init, move the high water mark computation into tcg_prologue_init.
--- tcg/tcg.c | 35 ++++++++++++++++++++++++++++------- translate-all.c | 28 +++++++++------------------- 2 files changed, 37 insertions(+), 26 deletions(-)
tcg/tcg.c +28 -7
@@ -363,17 +363,38 @@ void tcg_context_init(TCGContext *s)void tcg_prologue_init (TCGContext *s) { -/* init global prologue and epilogue */ - s->code_buf = s->code_gen_prologue; - s->code_ptr = s->code_buf; +size_t prologue_size, total_size; +void *buf0, *buf1; + +/* Put the prologue at the beginning of code_gen_buffer. */ + buf0 = s->code_gen_buffer; + s->code_ptr = buf0; + s->code_buf = buf0; + s->code_gen_prologue = buf0; + +/* Generate the prologue. */ tcg_target_qemu_prologue (s); -flush_icache_range ((uintptr_t )s->code_buf, (uintptr_t )s->code_ptr); + buf1 = s->code_ptr; +flush_icache_range ((uintptr_t )buf0, (uintptr_t )buf1); + +/* Deduct the prologue from the buffer. */ + prologue_size =tcg_current_code_size (s); + s->code_gen_ptr = buf1; + s->code_gen_buffer = buf1; + s->code_buf = buf1; + total_size = s->code_gen_buffer_size - prologue_size; + s->code_gen_buffer_size = total_size; + +/* Compute a high-water mark, at which we voluntarily flush the +buffer and start over. */ + s->code_gen_buffer_max_size = total_size -TCG_MAX_OP_SIZE *OPC_BUF_SIZE ; + +tcg_register_jit (s->code_gen_buffer, total_size);#ifdef DEBUG_DISAS if (qemu_loglevel_mask (CPU_LOG_TB_OUT_ASM )) { -size_t size =tcg_current_code_size (s); -qemu_log ("PROLOGUE: [size=%zu]\n" , size); -log_disas (s->code_buf, size); +qemu_log ("PROLOGUE: [size=%zu]\n" , prologue_size); +log_disas (buf0, prologue_size);qemu_log ("\n" );qemu_log_flush (); }
translate-all.c +9 -19
@@ -690,23 +690,15 @@ static inline void code_gen_alloc(size_t tb_size) }qemu_madvise (tcg_ctx.code_gen_buffer, tcg_ctx.code_gen_buffer_size, -QEMU_MADV_HUGEPAGE ); - -/* Steal room for the prologue at the end of the buffer. This ensures -(via the MAX_CODE_GEN_BUFFER_SIZE limits above) that direct branches -from TB's to the prologue are going to be in range. It also means -that we don't need to mark (additional) portions of the data segment -as executable. */ - tcg_ctx.code_gen_prologue = tcg_ctx.code_gen_buffer + - tcg_ctx.code_gen_buffer_size -1024 ; - tcg_ctx.code_gen_buffer_size -=1024 ; - - tcg_ctx.code_gen_buffer_max_size = tcg_ctx.code_gen_buffer_size - - (TCG_MAX_OP_SIZE *OPC_BUF_SIZE ); - tcg_ctx.code_gen_max_blocks = tcg_ctx.code_gen_buffer_size / -CODE_GEN_AVG_BLOCK_SIZE ; - tcg_ctx.tb_ctx.tbs = -g_malloc (tcg_ctx.code_gen_max_blocks *sizeof (TranslationBlock)); +QEMU_MADV_HUGEPAGE ); + +/* Estimate a good size for the number of TBs we can support. We +still haven't deducted the prologue from the buffer size here, +but that's minimal and won't affect the estimate much. */ + tcg_ctx.code_gen_max_blocks + = tcg_ctx.code_gen_buffer_size /CODE_GEN_AVG_BLOCK_SIZE ; + tcg_ctx.tb_ctx.tbs =g_new (TranslationBlock, tcg_ctx.code_gen_max_blocks); +qemu_mutex_init (&tcg_ctx.tb_ctx.tb_lock); }
@@ -717,8 +709,6 @@ void tcg_exec_init(unsigned long tb_size) {cpu_gen_init ();code_gen_alloc (tb_size); - tcg_ctx.code_gen_ptr = tcg_ctx.code_gen_buffer; -tcg_register_jit (tcg_ctx.code_gen_buffer, tcg_ctx.code_gen_buffer_size);page_init ();#if defined(CONFIG_SOFTMMU )/* There's no guest base to take into account, so go ahead and
Signature · 1 line
2.4.3
PATCH v4 24/26 tcg: Allocate a guard page after code_gen_buffer
In reply to Richard HendersonThis will catch any overflow of the buffer.
Add a native win32 alternative for alloc_code_gen_buffer; remove the malloc alternative.
--- translate-all.c | 210 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 119 insertions(+), 91 deletions(-)
translate-all.c +119 -91
@@ -312,31 +312,6 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr)return false; } -#ifdef _WIN32 -static __attribute__((unused))void map_exec (void *addr,long size) -{ -DWORD old_protect; -VirtualProtect (addr, size, -PAGE_EXECUTE_READWRITE , &old_protect); -} -#else -static __attribute__((unused))void map_exec (void *addr,long size) -{ -unsigned long start, end, page_size; - - page_size =getpagesize (); - start = (unsigned long )addr; - start &= ~(page_size -1 ); - - end = (unsigned long )addr + size; - end += page_size -1 ; - end &= ~(page_size -1 ); - -mprotect ((void *)start, end - start, -PROT_READ |PROT_WRITE |PROT_EXEC ); -} -#endif -void page_size_init (void ) {/* NOTE: we can always suppose that qemu_host_page_size >=
@@ -473,14 +448,6 @@ static inline PageDesc *page_find(tb_page_addr_t index)#define USE_STATIC_CODE_GEN_BUFFER #endif -/* ??? Should configure for this, not list operating systems here. */ -#if (defined(__linux__) \ - || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \ - || defined(__DragonFly__) || defined(__OpenBSD__) \ - || defined(__NetBSD__)) -# define USE_MMAP -#endif -/* Minimum size of the code gen buffer. This number is randomly chosen, but not so small that we can't have a fair number of TB's live. */ #define MIN_CODE_GEN_BUFFER_SIZE (1024u * 1024)
@@ -568,22 +535,102 @@ static inline void *split_cross_256mb(void *buf1, size_t size1) static uint8_t static_code_gen_buffer[DEFAULT_CODE_GEN_BUFFER_SIZE] __attribute__((aligned(CODE_GEN_ALIGN))); +# ifdef _WIN32 +static inline void do_protect (void *addr,long size,int prot) +{ +DWORD old_protect; +VirtualProtect (addr, size, prot, &old_protect); +} + +static inline void map_exec (void *addr,long size) +{ +do_protect (addr, size,PAGE_EXECUTE_READWRITE ); +} + +static inline void map_none (void *addr,long size) +{ +do_protect (addr, size,PAGE_NOACCESS ); +} +# else +static inline void do_protect (void *addr,long size,int prot) +{ +uintptr_t start, end; + + start = (uintptr_t )addr; + start &= qemu_real_host_page_mask; + + end = (uintptr_t )addr + size; + end =ROUND_UP (end, qemu_real_host_page_size); + +mprotect ((void *)start, end - start, prot); +} + +static inline void map_exec (void *addr,long size) +{ +do_protect (addr, size,PROT_READ |PROT_WRITE |PROT_EXEC ); +} + +static inline void map_none (void *addr,long size) +{ +do_protect (addr, size,PROT_NONE ); +} +# endif /* WIN32 */ +static inline void *alloc_code_gen_buffer (void ) {void *buf = static_code_gen_buffer; +size_t full_size, size; + +/* The size of the buffer, rounded down to end on a page boundary. */ + full_size = (((uintptr_t )buf +sizeof (static_code_gen_buffer)) + & qemu_real_host_page_mask) - (uintptr_t )buf; + +/* Reserve a guard page. */ + size = full_size - qemu_real_host_page_size; + +/* Honor a command-line option limiting the size of the buffer. */ +if (size > tcg_ctx.code_gen_buffer_size) { + size = (((uintptr_t )buf + tcg_ctx.code_gen_buffer_size) + & qemu_real_host_page_mask) - (uintptr_t )buf; + } + tcg_ctx.code_gen_buffer_size = size; +#ifdef __mips__ -if (cross_256mb (buf, tcg_ctx.code_gen_buffer_size)) { - buf =split_cross_256mb (buf, tcg_ctx.code_gen_buffer_size); +if (cross_256mb (buf, size)) { + buf =split_cross_256mb (buf, size); + size = tcg_ctx.code_gen_buffer_size; }#endif -map_exec (buf, tcg_ctx.code_gen_buffer_size); + +map_exec (buf, size); +map_none (buf + size, qemu_real_host_page_size); +qemu_madvise (buf, size,QEMU_MADV_HUGEPAGE ); +return buf; } -#elif defined(USE_MMAP ) +#elif defined(_WIN32) +static inline void *alloc_code_gen_buffer (void ) +{ +size_t size = tcg_ctx.code_gen_buffer_size; +void *buf1, *buf2; + +/* Perform the allocation in two steps, so that the guard page +is reserved but uncommitted. */ + buf1 =VirtualAlloc (NULL , size + qemu_real_host_page_size, +MEM_RESERVE ,PAGE_NOACCESS ); +if (buf1 !=NULL ) { + buf2 =VirtualAlloc (buf1, size,MEM_COMMIT ,PAGE_EXECUTE_READWRITE ); +assert (buf1 == buf2); + } + +return buf1; +} +#else static inline void *alloc_code_gen_buffer (void ) {int flags =MAP_PRIVATE |MAP_ANONYMOUS ;uintptr_t start =0 ; +size_t size = tcg_ctx.code_gen_buffer_size;void *buf;/* Constrain the position of the buffer based on the host cpu.
@@ -599,86 +646,70 @@ static inline void *alloc_code_gen_buffer(void)Leave the choice of exact location with the kernel. */ flags |=MAP_32BIT ;/* Cannot expect to map more than 800MB in low memory. */ -if (tcg_ctx.code_gen_buffer_size >800u *1024 *1024 ) { - tcg_ctx.code_gen_buffer_size =800u *1024 *1024 ; +if (size >800u *1024 *1024 ) { + tcg_ctx.code_gen_buffer_size = size =800u *1024 *1024 ; }# elif defined(__sparc__) start =0x40000000ul ;# elif defined(__s390x__) start =0x90000000ul ;# elif defined(__mips__) -/* ??? We ought to more explicitly manage layout for softmmu too. */ -# ifdef CONFIG_USER_ONLY - start =0x68000000ul ; -# elif _MIPS_SIM == _ABI64 +# if _MIPS_SIM == _ABI64 start =0x128000000ul ;# else start =0x08000000ul ;# endif # endif - buf =mmap ((void *)start, tcg_ctx.code_gen_buffer_size, -PROT_WRITE |PROT_READ |PROT_EXEC , flags,-1 ,0 ); + buf =mmap ((void *)start, size + qemu_real_host_page_size, +PROT_NONE , flags,-1 ,0 );if (buf ==MAP_FAILED ) {return NULL ; }#ifdef __mips__ -if (cross_256mb (buf, tcg_ctx.code_gen_buffer_size)) { +if (cross_256mb (buf, size)) {/* Try again, with the original still mapped, to avoid re-acquiring that 256mb crossing. This time don't specify an address. */ -size_t size2, size1 = tcg_ctx.code_gen_buffer_size; -void *buf2 =mmap (NULL , size1,PROT_WRITE |PROT_READ |PROT_EXEC , - flags,-1 ,0 ); -if (buf2 !=MAP_FAILED ) { -if (!cross_256mb (buf2, size1)) { +size_t size2; +void *buf2 =mmap (NULL , size + qemu_real_host_page_size, +PROT_NONE , flags,-1 ,0 ); +switch (buf2 !=MAP_FAILED ) { +case 1 : +if (!cross_256mb (buf2, size)) {/* Success! Use the new buffer. */ -munmap (buf, size1); -return buf2; +munmap (buf, size); +break ; }/* Failure. Work with what we had. */ -munmap (buf2, size1); +munmap (buf2, size); +/* fallthru */ +default : +/* Split the original buffer. Free the smaller half. */ + buf2 =split_cross_256mb (buf, size); + size2 = tcg_ctx.code_gen_buffer_size; +if (buf == buf2) { +munmap (buf + size2 + qemu_real_host_page_size, size - size2); + }else { +munmap (buf, size - size2); + } + size = size2; +break ; } - -/* Split the original buffer. Free the smaller half. */ - buf2 =split_cross_256mb (buf, size1); - size2 = tcg_ctx.code_gen_buffer_size; -munmap (buf + (buf == buf2 ? size2 :0 ), size1 - size2); -return buf2; + buf = buf2; }#endif -return buf; -} -#else -static inline void *alloc_code_gen_buffer (void ) -{ -void *buf =g_try_malloc (tcg_ctx.code_gen_buffer_size); +/* Make the final buffer accessible. The guard page at the end +will remain inaccessible with PROT_NONE. */ +mprotect (buf, size,PROT_WRITE |PROT_READ |PROT_EXEC ); -if (buf ==NULL ) { -return NULL ; - } +/* Request large pages for the buffer. */ +qemu_madvise (buf, size,QEMU_MADV_HUGEPAGE ); -#ifdef __mips__ -if (cross_256mb (buf, tcg_ctx.code_gen_buffer_size)) { -void *buf2 =g_malloc (tcg_ctx.code_gen_buffer_size); -if (buf2 !=NULL && !cross_256mb (buf2, size1)) { -/* Success! Use the new buffer. */ -free (buf); - buf = buf2; - }else { -/* Failure. Work with what we had. Since this is malloc -and not mmap, we can't free the other half. */ -free (buf2); - buf =split_cross_256mb (buf, tcg_ctx.code_gen_buffer_size); - } - } -#endif - -map_exec (buf, tcg_ctx.code_gen_buffer_size); return buf; } -#endif /* USE_STATIC_CODE_GEN_BUFFER, USE_MMAP */ +#endif /* USE_STATIC_CODE_GEN_BUFFER, WIN32, POSIX */ static inline void code_gen_alloc (size_t tb_size) {
@@ -689,9 +720,6 @@ static inline void code_gen_alloc(size_t tb_size)exit (1 ); } -qemu_madvise (tcg_ctx.code_gen_buffer, tcg_ctx.code_gen_buffer_size, -QEMU_MADV_HUGEPAGE ); -/* Estimate a good size for the number of TBs we can support. We still haven't deducted the prologue from the buffer size here, but that's minimal and won't affect the estimate much. */
@@ -708,8 +736,8 @@ static inline void code_gen_alloc(size_t tb_size)void tcg_exec_init (unsigned long tb_size) {cpu_gen_init (); -code_gen_alloc (tb_size);page_init (); +code_gen_alloc (tb_size);#if defined(CONFIG_SOFTMMU )/* There's no guest base to take into account, so go ahead and initialize the prologue now. */
Signature · 1 line
2.4.3
PATCH v4 25/26 tcg: Check for overflow via highwater mark
In reply to Richard HendersonWe currently pre-compute an worst case code size for any TB, which works out to be 122kB. Since the average TB size is near 1kB, this wastes quite a lot of storage.
Instead, check for overflow in between generating code for each opcode. The overhead of the check isn't measurable and wastage is minimized.
--- include/exec/exec-all.h | 6 ------ tcg/tcg.c | 14 +++++++++++--- tcg/tcg.h | 5 +++-- translate-all.c | 31 ++++++++++++++++++++++++++----- 4 files changed, 40 insertions(+), 16 deletions(-)
include/exec/exec-all.h +0 -6
@@ -62,12 +62,6 @@ typedef struct TranslationBlock TranslationBlock;#define OPC_BUF_SIZE 640#define OPC_MAX_SIZE (OPC_BUF_SIZE - MAX_OP_PER_INSTR) -/* Maximum size a TCG op can expand to. This is complicated because a -single op may require several host instructions and register reloads. -For now take a wild guess at 192 bytes, which should allow at least -a couple of fixup instructions per argument. */ -#define TCG_MAX_OP_SIZE 192 -#define OPPARAM_BUF_SIZE (OPC_BUF_SIZE * MAX_OPC_PARAM)#include "qemu/log.h"
tcg/tcg.c +11 -3
@@ -385,9 +385,10 @@ void tcg_prologue_init(TCGContext *s) total_size = s->code_gen_buffer_size - prologue_size; s->code_gen_buffer_size = total_size; -/* Compute a high-water mark, at which we voluntarily flush the -buffer and start over. */ - s->code_gen_buffer_max_size = total_size -TCG_MAX_OP_SIZE *OPC_BUF_SIZE ; +/* Compute a high-water mark, at which we voluntarily flush the buffer +and start over. The size here is arbitrary, significantly larger +than we expect the code generation for any one opcode to require. */ + s->code_gen_highwater = s->code_gen_buffer + (total_size -1024 );tcg_register_jit (s->code_gen_buffer, total_size);
@@ -2438,6 +2439,13 @@ int tcg_gen_code(TCGContext *s, tcg_insn_unit *gen_code_buf)#ifndef NDEBUG check_regs (s);#endif +/* Test for (pending) buffer overflow. The assumption is that any +one operation beginning below the high water mark cannot overrun +the buffer completely. Thus we can test for overflow after +generating code without having to check during generation. */ +if (unlikely (s->code_gen_ptr > s->code_gen_highwater)) { +return -1 ; + } }tcg_debug_assert (num_insns >=0 ); s->gen_insn_end_off[num_insns] =tcg_current_code_size (s);
tcg/tcg.h +3 -2
@@ -559,10 +559,11 @@ struct TCGContext {void *code_gen_prologue;void *code_gen_buffer;size_t code_gen_buffer_size; -/* threshold to flush the translated code buffer */ -size_t code_gen_buffer_max_size;void *code_gen_ptr; +/* Threshold to flush the translated code buffer. */ +void *code_gen_highwater; +TBContext tb_ctx;/* The TCGBackendData structure is private to tcg-target.c. */
translate-all.c +26 -5
@@ -223,6 +223,7 @@ static target_long decode_sleb128(uint8_t **pp)static int encode_search (TranslationBlock *tb,uint8_t *block) { +uint8_t *highwater = tcg_ctx.code_gen_highwater;uint8_t *p = block;int i, j, n;
@@ -241,6 +242,14 @@ static int encode_search(TranslationBlock *tb, uint8_t *block) } prev = (i ==0 ?0 : tcg_ctx.gen_insn_end_off[i -1 ]); p =encode_sleb128 (p, tcg_ctx.gen_insn_end_off[i] - prev); + +/* Test for (pending) buffer overflow. The assumption is that any +one row beginning below the high water mark cannot overrun +the buffer completely. Thus we can test for overflow after +encoding a row without having to check during encoding. */ +if (unlikely (p > highwater)) { +return -1 ; + } }return p - block;
@@ -756,9 +765,7 @@ static TranslationBlock *tb_alloc(target_ulong pc) {TranslationBlock *tb; -if (tcg_ctx.tb_ctx.nb_tbs >= tcg_ctx.code_gen_max_blocks || - (tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer) >= - tcg_ctx.code_gen_buffer_max_size) { +if (tcg_ctx.tb_ctx.nb_tbs >= tcg_ctx.code_gen_max_blocks) {return NULL ; } tb = &tcg_ctx.tb_ctx.tbs[tcg_ctx.tb_ctx.nb_tbs++];
@@ -1063,12 +1070,15 @@ TranslationBlock *tb_gen_code(CPUState *cpu,if (use_icount) { cflags |=CF_USE_ICOUNT ; } + tb =tb_alloc (pc); -if (!tb) { +if (unlikely (!tb)) { + buffer_overflow:/* flush must be done */ tb_flush (cpu);/* cannot fail at this point */ tb =tb_alloc (pc); +assert (tb !=NULL );/* Don't forget to invalidate previous TB info. */ tcg_ctx.tb_ctx.tb_invalidated_flag =1 ; }
@@ -1109,8 +1119,19 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tcg_ctx.code_time -=profile_getclock ();#endif +/* ??? Overflow could be handled better here. In particular, we +don't need to re-do gen_intermediate_code, nor should we re-do +the tcg optimization currently hidden inside tcg_gen_code. All +that should be required is to flush the TBs, allocate a new TB, +re-initialize it per above, and re-do the actual code generation. */ gen_code_size =tcg_gen_code (&tcg_ctx, gen_code_buf); +if (unlikely (gen_code_size <0 )) { + goto buffer_overflow; + } search_size =encode_search (tb, (void *)gen_code_buf + gen_code_size); +if (unlikely (search_size <0 )) { + goto buffer_overflow; + }#ifdef CONFIG_PROFILER tcg_ctx.code_time +=profile_getclock ();
@@ -1681,7 +1702,7 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf)cpu_fprintf (f,"Translation buffer state:\n" );cpu_fprintf (f,"gen code size %td/%zd\n" , tcg_ctx.code_gen_ptr - tcg_ctx.code_gen_buffer, - tcg_ctx.code_gen_buffer_max_size); + tcg_ctx.code_gen_highwater - tcg_ctx.code_gen_buffer);cpu_fprintf (f,"TB count %d/%d\n" , tcg_ctx.tb_ctx.nb_tbs, tcg_ctx.code_gen_max_blocks); cpu_fprintf(f, "TB avg target size %d max=%d bytes\n",
Signature · 1 line
2.4.3
PATCH v4 26/26 tcg: Adjust CODE_GEN_AVG_BLOCK_SIZE
In reply to Richard HendersonAt present, the "average" guestimate of TB size is way too small, leading to many unused entries in the pre-allocated TB array. For a guest with 1GB ram, we're currently allocating 256MB for the array.
Survey arm, alpha, aarch64, ppc, sparc, i686, x86_64 guests running on x86_64 and ppc64 hosts and select a new average. The size of the array drops to 81MB with no more flushing than before.
--- include/exec/exec-all.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
include/exec/exec-all.h +6 -5
@@ -161,13 +161,14 @@ static inline void tlb_flush_by_mmuidx(CPUState *cpu, ...)#define CODE_GEN_PHYS_HASH_BITS 15#define CODE_GEN_PHYS_HASH_SIZE (1 << CODE_GEN_PHYS_HASH_BITS) -/* estimated block size for TB allocation */ -/* XXX: use a per code average code fragment size and modulate it -according to the host CPU */ +/* Estimated block size for TB allocation. */ +/* ??? The following is based on a 2015 survey of x86_64 host output. +Better would seem to be some sort of dynamically sized TB array, +adapting to the block sizes actually being produced. */ #if defined(CONFIG_SOFTMMU ) -#define CODE_GEN_AVG_BLOCK_SIZE 128 +#define CODE_GEN_AVG_BLOCK_SIZE 400#else -#define CODE_GEN_AVG_BLOCK_SIZE 64 +#define CODE_GEN_AVG_BLOCK_SIZE 150#endif #if defined(__arm__) || defined(_ARCH_PPC) \
Signature · 1 line
2.4.3
PATCH v4 1/26 tcg: Rename debug_insn_start to insn_start
In reply to Richard HendersonWith an eye toward making it mandatory.
--- target-alpha/translate.c | 2 +- target-arm/translate-a64.c | 2 +- target-arm/translate.c | 2 +- target-cris/translate.c | 4 ++-- target-cris/translate_v10.c | 2 +- target-i386/translate.c | 2 +- target-lm32/translate.c | 2 +- target-m68k/translate.c | 2 +- target-microblaze/translate.c | 2 +- target-mips/translate.c | 2 +- target-moxie/translate.c | 2 +- target-openrisc/translate.c | 2 +- target-ppc/translate.c | 2 +- target-s390x/translate.c | 2 +- target-sh4/translate.c | 2 +- target-sparc/translate.c | 2 +- target-tilegx/translate.c | 2 +- target-unicore32/translate.c | 2 +- target-xtensa/translate.c | 2 +- tcg/tcg-op.h | 6 +++--- tcg/tcg-opc.h | 4 ++-- tcg/tcg.c | 6 +++--- tci.c | 9 --------- 23 files changed, 28 insertions(+), 37 deletions(-)
target-alpha/translate.c +1 -1
@@ -2940,7 +2940,7 @@ static inline void gen_intermediate_code_internal(AlphaCPU *cpu, num_insns++;if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (ctx.pc); +tcg_gen_insn_start (ctx.pc); }TCGV_UNUSED_I64 (ctx.zero);
target-arm/translate-a64.c +1 -1
@@ -11109,7 +11109,7 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu, }if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (dc->pc); +tcg_gen_insn_start (dc->pc); }if (dc->ss_active && !dc->pstate_ss) {
target-arm/translate.c +1 -1
@@ -11353,7 +11353,7 @@ static inline void gen_intermediate_code_internal(ARMCPU *cpu,gen_io_start ();if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (dc->pc); +tcg_gen_insn_start (dc->pc); }if (dc->ss_active && !dc->pstate_ss) {
target-cris/translate.c +2 -2
@@ -2995,8 +2995,8 @@ static unsigned int crisv32_decoder(CPUCRISState *env, DisasContext *dc)int i;if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (dc->pc); - } +tcg_gen_insn_start (dc->pc); + }/* Load a halfword onto the instruction register. */ dc->ir =cris_fetch (env, dc, dc->pc,2 ,0 );
target-cris/translate_v10.c +1 -1
@@ -1200,7 +1200,7 @@ static unsigned int crisv10_decoder(CPUCRISState *env, DisasContext *dc)unsigned int insn_len =2 ;if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP ))) -tcg_gen_debug_insn_start (dc->pc); +tcg_gen_insn_start (dc->pc);/* Load a halfword onto the instruction register. */ dc->ir =cpu_lduw_code (env, dc->pc);
target-i386/translate.c +1 -1
@@ -4402,7 +4402,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,int rex_w, rex_r;if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (pc_start); +tcg_gen_insn_start (pc_start); } s->pc = pc_start; prefixes =0 ;
target-lm32/translate.c +1 -1
@@ -1006,7 +1006,7 @@ static const DecoderInfo decinfo[] = {static inline void decode (DisasContext *dc,uint32_t ir) {if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (dc->pc); +tcg_gen_insn_start (dc->pc); } dc->ir = ir;
target-m68k/translate.c +1 -1
@@ -2956,7 +2956,7 @@ static void disas_m68k_insn(CPUM68KState * env, DisasContext *s)uint16_t insn;if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (s->pc); +tcg_gen_insn_start (s->pc); } insn =cpu_lduw_code (env, s->pc);
target-microblaze/translate.c +1 -1
@@ -1589,7 +1589,7 @@ static inline void decode(DisasContext *dc, uint32_t ir)int i;if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (dc->pc); +tcg_gen_insn_start (dc->pc); } dc->ir = ir;
target-mips/translate.c +1 -1
@@ -18905,7 +18905,7 @@ static void decode_opc(CPUMIPSState *env, DisasContext *ctx) }if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (ctx->pc); +tcg_gen_insn_start (ctx->pc); } op =MASK_OP_MAJOR (ctx->opcode);
target-moxie/translate.c +1 -1
@@ -154,7 +154,7 @@ static int decode_opc(MoxieCPU *cpu, DisasContext *ctx)int length =2 ;if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (ctx->pc); +tcg_gen_insn_start (ctx->pc); }/* Examine the 16-bit opcode. */
target-openrisc/translate.c +1 -1
@@ -1689,7 +1689,7 @@ static inline void gen_intermediate_code_internal(OpenRISCCPU *cpu, }if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (dc->pc); +tcg_gen_insn_start (dc->pc); }if (num_insns +1 == max_insns && (tb->cflags &CF_LAST_IO )) {
target-ppc/translate.c +1 -1
@@ -11516,7 +11516,7 @@ static inline void gen_intermediate_code_internal(PowerPCCPU *cpu, ctx.opcode,opc1 (ctx.opcode),opc2 (ctx.opcode), opc3(ctx.opcode), ctx.le_mode ? "little" : "big");if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (ctx.nip); +tcg_gen_insn_start (ctx.nip); } ctx.nip +=4 ; table = env->opcodes;
target-s390x/translate.c +1 -1
@@ -5375,7 +5375,7 @@ static inline void gen_intermediate_code_internal(S390CPU *cpu, }if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (dc.pc); +tcg_gen_insn_start (dc.pc); } status =NO_EXIT ;
target-sh4/translate.c +1 -1
@@ -1791,7 +1791,7 @@ static void decode_opc(DisasContext * ctx)uint32_t old_flags = ctx->flags;if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (ctx->pc); +tcg_gen_insn_start (ctx->pc); }_decode_opc (ctx);
target-sparc/translate.c +1 -1
@@ -2483,7 +2483,7 @@ static void disas_sparc_insn(DisasContext * dc, unsigned int insn)target_long simm;if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (dc->pc); +tcg_gen_insn_start (dc->pc); } opc =GET_FIELD (insn,0 ,1 );
target-tilegx/translate.c +1 -1
@@ -2009,7 +2009,7 @@ static void translate_one_bundle(DisasContext *dc, uint64_t bundle) dc->num_wb =0 ;if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (dc->pc); +tcg_gen_insn_start (dc->pc); }qemu_log_mask (CPU_LOG_TB_IN_ASM ," %" PRIx64": { " , dc->pc);
target-unicore32/translate.c +1 -1
@@ -1795,7 +1795,7 @@ static void disas_uc32_insn(CPUUniCore32State *env, DisasContext *s)unsigned int insn;if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (s->pc); +tcg_gen_insn_start (s->pc); } insn =cpu_ldl_code (env, s->pc);
target-xtensa/translate.c +1 -1
@@ -3078,7 +3078,7 @@ void gen_intermediate_code_internal(XtensaCPU *cpu, }if (unlikely (qemu_loglevel_mask (CPU_LOG_TB_OP |CPU_LOG_TB_OP_OPT ))) { -tcg_gen_debug_insn_start (dc.pc); +tcg_gen_insn_start (dc.pc); } ++dc.ccount_delta;
tcg/tcg-op.h +3 -3
@@ -701,14 +701,14 @@ static inline void tcg_gen_concat32_i64(TCGv_i64 ret, TCGv_i64 lo, TCGv_i64 hi)#endif /* debug info: write the PC of the corresponding QEMU CPU instruction */ -static inline void tcg_gen_debug_insn_start (uint64_t pc) +static inline void tcg_gen_insn_start (uint64_t pc) {/* XXX: must really use a 32 bit size for TCGArg in all cases */ #if TARGET_LONG_BITS >TCG_TARGET_REG_BITS -tcg_gen_op2ii (INDEX_op_debug_insn_start, +tcg_gen_op2ii (INDEX_op_insn_start, (uint32_t )(pc), (uint32_t )(pc >>32 ));#else -tcg_gen_op1i (INDEX_op_debug_insn_start, pc); +tcg_gen_op1i (INDEX_op_insn_start, pc);#endif }
tcg/tcg-opc.h +2 -2
@@ -175,9 +175,9 @@ DEF(mulsh_i64, 1, 2, 0, IMPL(TCG_TARGET_HAS_mulsh_i64))/* QEMU specific */ #if TARGET_LONG_BITS >TCG_TARGET_REG_BITS -DEF(debug_insn_start, 0, 0, 2, TCG_OPF_NOT_PRESENT) +DEF(insn_start, 0, 0, 2, TCG_OPF_NOT_PRESENT)#else -DEF(debug_insn_start, 0, 0, 1, TCG_OPF_NOT_PRESENT) +DEF(insn_start, 0, 0, 1, TCG_OPF_NOT_PRESENT)#endif DEF(exit_tb, 0, 0, 1, TCG_OPF_BB_END)DEF (goto_tb,0 ,0 ,1 ,TCG_OPF_BB_END )
tcg/tcg.c +3 -3
@@ -990,7 +990,7 @@ void tcg_dump_ops(TCGContext *s) def = &tcg_op_defs[c]; args = &s->gen_opparam_buf[op->args]; -if (c == INDEX_op_debug_insn_start) { +if (c == INDEX_op_insn_start) {uint64_t pc;#if TARGET_LONG_BITS >TCG_TARGET_REG_BITS pc = ((uint64_t )args[1 ] <<32 ) | args[0 ];
@@ -1400,7 +1400,7 @@ static void tcg_liveness_analysis(TCGContext *s) } }break ; -case INDEX_op_debug_insn_start: +case INDEX_op_insn_start:break ;case INDEX_op_discard:/* mark the temporary as dead */
@@ -2359,7 +2359,7 @@ static inline int tcg_gen_code_common(TCGContext *s,case INDEX_op_movi_i64:tcg_reg_alloc_movi (s, args, dead_args, sync_args);break ; -case INDEX_op_debug_insn_start: +case INDEX_op_insn_start:break ;case INDEX_op_discard:temp_dead (s, args[0 ]);
tci.c +0 -9
@@ -1081,15 +1081,6 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t *tb_ptr)/* QEMU specific operations. */ -#if TARGET_LONG_BITS >TCG_TARGET_REG_BITS -case INDEX_op_debug_insn_start: -TODO (); -break ; -#else -case INDEX_op_debug_insn_start: -TODO (); -break ; -#endif case INDEX_op_exit_tb: next_tb = *(uint64_t *)tb_ptr; goto exit;
Signature · 1 line
2.4.3
Re: [Qemu-devel] [PATCH v4 04/26] target-*: Introduce and use cpu_breakpoint_test
In reply to Richard HendersonQuoted 20 lines · Richard Henderson
Reduce the boilerplate required for each target. At the same time, move the test for breakpoint after calling
tcg_gen_insn_start.Note that arm and aarch64 do not use
cpu_breakpoint_test, but still move the inline test down aftertcg_gen_insn_start.Reviewed-by Peter Maydell <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- include/qom/cpu.h | 16 ++++++++++++++++ target-alpha/translate.c | 13 ++++--------- target-arm/translate-a64.c | 26 +++++++++++++------------- target-arm/translate.c | 31 ++++++++++++++++--------------- target-cris/translate.c | 27 ++++++++------------------- target-i386/translate.c | 17 +++++++---------- target-lm32/translate.c | 25 +++++++------------------ target-m68k/translate.c | 18 ++++++------------ target-microblaze/translate.c | 36 +++++++++++++----------------------- target-mips/translate.c | 25 ++++++++++--------------- target-moxie/translate.c | 19 +++++++------------
Quoted 8 lines
target-openrisc/translate.c | 24 +++++++----------------- target-ppc/translate.c | 14 +++++--------- target-s390x/translate.c | 16 ++++++---------- target-sh4/translate.c | 20 ++++++++------------ target-sparc/translate.c | 23 ++++++++++------------- target-unicore32/translate.c | 24 ++++++++++-------------- target-xtensa/translate.c | 25 +++++++------------------ 18 files changed, 160 insertions(+), 239 deletions(-)
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net
Re: [Qemu-devel] [PATCH v4 23/26] tcg: Emit prologue to the beginning of code_gen_buffer
In reply to Richard HendersonQuoted 11 lines · Richard Henderson
By putting the prologue at the end, we risk overwriting the prologue should our estimate of maximum TB size. Given the two different placements of the call to
tcg_prologue_init, move the high water mark computation intotcg_prologue_init.Reviewed-by Peter Maydell <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- tcg/tcg.c | 35 ++++++++++++++++++++++++++++------- translate-all.c | 28 +++++++++------------------- 2 files changed, 37 insertions(+), 26 deletions(-)
Good idea to move it. I have done some experiments with putting slow path "helpers" in the prologue, and I ended-up going over the 1024 bytes limits.
Quoted 29 lines
tcg/tcg.c +16
-4@@ -363,17 +363,38 @@ void tcg_context_init(TCGContext *s)void tcg_prologue_init (TCGContext *s) { -/* init global prologue and epilogue */ - s->code_buf = s->code_gen_prologue; - s->code_ptr = s->code_buf; +size_t prologue_size, total_size; +void *buf0, *buf1; + +/* Put the prologue at the beginning of code_gen_buffer. */ + buf0 = s->code_gen_buffer; + s->code_ptr = buf0; + s->code_buf = buf0; + s->code_gen_prologue = buf0; + +/* Generate the prologue. */ tcg_target_qemu_prologue (s); -flush_icache_range ((uintptr_t )s->code_buf, (uintptr_t )s->code_ptr); + buf1 = s->code_ptr; +flush_icache_range ((uintptr_t )buf0, (uintptr_t )buf1); + +/* Deduct the prologue from the buffer. */ + prologue_size =tcg_current_code_size (s); + s->code_gen_ptr = buf1;
tcg/tcg.c void tcg_context_init(TCGContext *s) · line 392
Quoted 10 lines
tcg/tcg.c +10
-0+ s->code_gen_buffer = buf1; + s->code_buf = buf1; + total_size = s->code_gen_buffer_size - prologue_size; + s->code_gen_buffer_size = total_size; + +/* Compute a high-water mark, at which we voluntarily flush the +buffer and start over. */ + s->code_gen_buffer_max_size = total_size -TCG_MAX_OP_SIZE *OPC_BUF_SIZE ; + +tcg_register_jit (s->code_gen_buffer, total_size);
I am not sure why you moved this 2 lines there, I think they have more their place in code_gen_alloc() so that the heuristics stay at the same place. total_size is available in s->code_gen_buffer_size, so that should be doable.
Quoted 48 lines
tcg/tcg.c +2
-3#ifdef DEBUG_DISAS if (qemu_loglevel_mask (CPU_LOG_TB_OUT_ASM )) { -size_t size =tcg_current_code_size (s); -qemu_log ("PROLOGUE: [size=%zu]\n" , size); -log_disas (s->code_buf, size); +qemu_log ("PROLOGUE: [size=%zu]\n" , prologue_size); +log_disas (buf0, prologue_size);qemu_log ("\n" );qemu_log_flush (); }translate-all.c +9
-17@@ -690,23 +690,15 @@ static inline void code_gen_alloc(size_t tb_size) }qemu_madvise (tcg_ctx.code_gen_buffer, tcg_ctx.code_gen_buffer_size, -QEMU_MADV_HUGEPAGE ); - -/* Steal room for the prologue at the end of the buffer. This ensures -(via the MAX_CODE_GEN_BUFFER_SIZE limits above) that direct branches -from TB's to the prologue are going to be in range. It also means -that we don't need to mark (additional) portions of the data segment -as executable. */ - tcg_ctx.code_gen_prologue = tcg_ctx.code_gen_buffer + - tcg_ctx.code_gen_buffer_size -1024 ; - tcg_ctx.code_gen_buffer_size -=1024 ; - - tcg_ctx.code_gen_buffer_max_size = tcg_ctx.code_gen_buffer_size - - (TCG_MAX_OP_SIZE *OPC_BUF_SIZE ); - tcg_ctx.code_gen_max_blocks = tcg_ctx.code_gen_buffer_size / -CODE_GEN_AVG_BLOCK_SIZE ; - tcg_ctx.tb_ctx.tbs = -g_malloc (tcg_ctx.code_gen_max_blocks *sizeof (TranslationBlock)); +QEMU_MADV_HUGEPAGE ); + +/* Estimate a good size for the number of TBs we can support. We +still haven't deducted the prologue from the buffer size here, +but that's minimal and won't affect the estimate much. */ + tcg_ctx.code_gen_max_blocks + = tcg_ctx.code_gen_buffer_size /CODE_GEN_AVG_BLOCK_SIZE ; + tcg_ctx.tb_ctx.tbs =g_new (TranslationBlock, tcg_ctx.code_gen_max_blocks); +qemu_mutex_init (&tcg_ctx.tb_ctx.tb_lock); }
translate-all.c void tcg_exec_init(unsigned long tb_size) · line 714
Quoted 8 lines
translate-all.c +0
-2@@ -717,8 +709,6 @@ void tcg_exec_init(unsigned long tb_size) {cpu_gen_init ();code_gen_alloc (tb_size); - tcg_ctx.code_gen_ptr = tcg_ctx.code_gen_buffer; -tcg_register_jit (tcg_ctx.code_gen_buffer, tcg_ctx.code_gen_buffer_size);page_init ();#if defined(CONFIG_SOFTMMU )/* There's no guest base to take into account, so go ahead and
Otherwise the patch looks fine to me.
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net
Re: [Qemu-devel] [PATCH v4 24/26] tcg: Allocate a guard page after code_gen_buffer
In reply to Richard HendersonQuoted 9 lines · Richard Henderson
This will catch any overflow of the buffer.
Add a native win32 alternative for
alloc_code_gen_buffer; remove the malloc alternative.Signed-off-by Richard Henderson <[email protected]>--- translate-all.c | 210 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 119 insertions(+), 91 deletions(-)
I havent reviewed the patch in details, but I wonder if that could really happen? Given the size of the code generation buffer (a few MB at least), I don't think it's a problem if we don't use it to the last kB, and thus we could keep some safe margin if needed.
Also what happens if an overflow really happens? In softmmu mode a segmentation fault will happen. In user-mode I guess the fault will be forwarded to the guest process, so this will likely wrongly be interpreted as a bug in the guest code.
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net
Re: [Qemu-devel] [PATCH v4 25/26] tcg: Check for overflow via highwater mark
In reply to Richard HendersonQuoted 3 lines · Richard Henderson
We currently pre-compute an worst case code size for any TB, which works out to be 122kB. Since the average TB size is near 1kB, this wastes quite a lot of storage.
The code generation buffer is currently computed as 1/4 of the guest RAM in softmmu mode (so 32MB for the default 128MB of RAM) or 32MB in user mode. 122kB is therefore less than 0.4% of waster memory, I am not therefore sure we need to add so much code just for that.
BTW, I wonder if it is really a good idea to scale the code generation buffer with the size of the RAM, as the two do not seem that related. It happens that at some point we don't really increases performances anymore, and always defining it as 32MB might actually be a good idea. Personally I am using a patch that limits it to 128MB.
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net
Re: [Qemu-devel] [PATCH v4 26/26] tcg: Adjust CODE_GEN_AVG_BLOCK_SIZE
In reply to Richard HendersonQuoted 4 lines · Richard Henderson
At present, the "average" guestimate of TB size is way too small, leading to many unused entries in the pre-allocated TB array. For a guest with 1GB ram, we're currently allocating 256MB for the array.
Quoted 8 lines
Survey arm, alpha, aarch64, ppc, sparc, i686,
x86_64guests running onx86_64and ppc64 hosts and select a new average. The size of the array drops to 81MB with no more flushing than before.Signed-off-by Richard Henderson <[email protected]>--- include/exec/exec-all.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net
Re: [Qemu-devel] [PATCH v4 25/26] tcg: Check for overflow via highwater mark
In reply to Aurelien JarnoQuoted 9 lines · Aurelien Jarno
Quoted 3 lines · Richard Henderson
We currently pre-compute an worst case code size for any TB, which works out to be 122kB. Since the average TB size is near 1kB, this wastes quite a lot of storage.
The code generation buffer is currently computed as 1/4 of the guest RAM in softmmu mode (so 32MB for the default 128MB of RAM) or 32MB in user mode. 122kB is therefore less than 0.4% of waster memory, I am not therefore sure we need to add so much code just for that.
I think the best argument for this patch is that it gets rid of the TCG_MAX_OP_SIZE guesswork about TCG op worst-cases. That sort of #define is generally arbitrary and liable to not get updated when new targets or backends invalidate previous assumptions.
(Can we do anything to get rid of MAX_OP_PER_INSTR too?)
thanks
-- PMM
Quoted 78 lines · Richard Henderson
Version 4:
* Typos noticed by pmm during round 3.
* RB's collected during round 3.
* Reduce the number of TBs allocated.I believe the only patch left without an RB is 24; and of course 26 which is new.
r~
Richard Henderson (26):
tcg: Renamedebug_insn_starttoinsn_start
target-*: Unconditionally emittcg_gen_insn_starttarget-*: Incrementnum_insnsimmediately aftertcg_gen_insn_starttarget-*: Introduce and usecpu_breakpoint_test
tcg: Allow extra data to be attached toinsn_start
target-arm: Add condexec state toinsn_start
target-i386: Addcc_opstate toinsn_start
target-mips: Add delayed branch state toinsn_start
target-s390x: Addcc_opstate toinsn_start
target-sh4: Add flags state toinsn_start
target-cris: Mirrorgen_opc_pcintoinsn_start
target-sparc: Tidygen_branch_ainterface
target-sparc: Split outgen_branch_n
target-sparc: Removegen_opc_jump_pc
target-sparc: Add npc state toinsn_start
tcg: Mergecpu_gen_codeintotb_gen_code
target-*: Dropcpu_gen_codedefine
tcg: AddTCG_MAX_INSNS
tcg: Pass data argument torestore_state_to_opc
tcg: Save insn data and use it incpu_restore_state_from_tb
tcg: Removegen_intermediate_code_pc
tcg: Removetcg_gen_code_search_pc
tcg: Emit prologue to the beginning ofcode_gen_buffer
tcg: Allocate a guard page aftercode_gen_buffer
tcg: Check for overflow via highwater mark
tcg: AdjustCODE_GEN_AVG_BLOCK_SIZEinclude/exec/exec-all.h | 23 +- include/qom/cpu.h | 16 ++ target-alpha/cpu.h | 1 - target-alpha/translate.c | 70 ++---- target-arm/cpu.h | 2 +- target-arm/translate-a64.c | 48 +--- target-arm/translate.c | 83 +++---- target-arm/translate.h | 8 +- target-cris/cpu.h | 1 - target-cris/translate.c | 93 ++------ target-cris/translate_v10.c | 3 - target-i386/cpu.h | 2 +- target-i386/translate.c | 106 +++------ target-lm32/cpu.h | 1 - target-lm32/translate.c | 83 ++----- target-m68k/cpu.h | 1 - target-m68k/translate.c | 82 ++----- target-microblaze/cpu.h | 1 - target-microblaze/translate.c | 83 ++----- target-mips/cpu.h | 2 +- target-mips/translate.c | 98 +++----- target-moxie/cpu.h | 1 - target-moxie/translate.c | 82 +++---- target-openrisc/cpu.h | 1 - target-openrisc/translate.c | 78 ++----- target-ppc/cpu.h | 1 - target-ppc/translate.c | 72 ++---- target-s390x/cpu.h | 2 +- target-s390x/translate.c | 78 ++----- target-sh4/cpu.h | 2 +- target-sh4/translate.c | 91 +++----- target-sparc/cpu.h | 2 +- target-sparc/translate.c | 185 +++++++-------- target-tilegx/cpu.h | 1 - target-tilegx/translate.c | 58 ++--- target-tricore/translate.c | 59 ++--- target-unicore32/translate.c | 83 ++----- target-xtensa/cpu.h | 1 -
Quoted 8 lines
target-xtensa/translate.c | 79 ++----- tcg/tcg-op.h | 52 ++++- tcg/tcg-opc.h | 4 +- tcg/tcg.c | 168 ++++++++------ tcg/tcg.h | 20 +- tci.c | 9 - translate-all.c | 520 +++++++++++++++++++++++++----------------- 45 files changed, 964 insertions(+), 1492 deletions(-)
I have finally been able to review this whole patchset, sorry for the time it took. Thanks a lot for working on that, I think it's really a great improvement, both in term of performances, and in code cleanup (look at the final diff above). It's probably possible to do some more code cleaning after it's applied, but that should wait until this patchset is applied. There is at least the "do not change the jump target while retranslating" code in a few TCG targets that can be removed.
As said while reviewing this patchset, it opens some place for more improvements (like not saving data for instructions which can't trigger exceptions), but that should come after it has been applied.
On this subject, I believe this patchset is now a good state, except maybe for the last few patches. I am running an earlier version of it on plenty of VM without any issue, except on SH4. I realized SH4 broken in some rare cases, but not directly by this patchset. There is an issue when a delay slot is split in two parts when reaching the maximum number of TCG ops. Given the patch 2 adds more TCG ops, it triggers more often. It is already possible to trigger this issue, so this should not be consider as a blocker. I'll work on a fix ASAP, which might still takes some time given my current load.
Aurelien
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net
Re: [Qemu-devel] [PATCH v4 24/26] tcg: Allocate a guard page after code_gen_buffer
In reply to Aurelien JarnoQuoted 11 lines · Aurelien Jarno
Quoted 9 lines · Richard Henderson
This will catch any overflow of the buffer.
Add a native win32 alternative for
alloc_code_gen_buffer; remove the malloc alternative.Signed-off-by Richard Henderson <[email protected]>--- translate-all.c | 210 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 119 insertions(+), 91 deletions(-)
Quoted 4 lines
I havent reviewed the patch in details, but I wonder if that could really happen? Given the size of the code generation buffer (a few MB at least), I don't think it's a problem if we don't use it to the last kB, and thus we could keep some safe margin if needed.
I don't believe that it can happen at the moment, given the size of the current "safe margin". But the subject came up during review, and I thought we should indeed do something about it.
Quoted 4 lines
Also what happens if an overflow really happens? In softmmu mode a segmentation fault will happen. In user-mode I guess the fault will be forwarded to the guest process, so this will likely wrongly be interpreted as a bug in the guest code.
You're right. I had thought that we tested page_check_range on the given address in user-mode before passing it on to the guest.
In any case, that's how to fix the problem you indicate...
r~
Re: [Qemu-devel] [PATCH v4 25/26] tcg: Check for overflow via highwater mark
In reply to Aurelien JarnoQuoted 10 lines · Aurelien Jarno
Quoted 3 lines · Richard Henderson
We currently pre-compute an worst case code size for any TB, which works out to be 122kB. Since the average TB size is near 1kB, this wastes quite a lot of storage.
The code generation buffer is currently computed as 1/4 of the guest RAM in softmmu mode (so 32MB for the default 128MB of RAM) or 32MB in user mode. 122kB is therefore less than 0.4% of waster memory, I am not therefore sure we need to add so much code just for that.
Quoted 5 lines
BTW, I wonder if it is really a good idea to scale the code generation buffer with the size of the RAM, as the two do not seem that related. It happens that at some point we don't really increases performances anymore, and always defining it as 32MB might actually be a good idea. Personally I am using a patch that limits it to 128MB.
It depends on the guest and the workload I suppose.
For alpha, which almost never flushes the buffer, allocating 2GB to the guest (and thus 512MB to the buffer) seems to reach a nice steady-state during a guest gcc bootstrap where no more code generation is required.
If I were to limit the buffer to significantly less, as you're suggesting, I believe that the working set would overflow the buffer, requiring more code generation.
I guess I could always use -tb-size myself to override...
r~
Re: [Qemu-devel] [PATCH v4 23/26] tcg: Emit prologue to the beginning of code_gen_buffer
In reply to Aurelien JarnoQuoted 53 lines · Aurelien Jarno
Quoted 11 lines · Richard Henderson
By putting the prologue at the end, we risk overwriting the prologue should our estimate of maximum TB size. Given the two different placements of the call to
tcg_prologue_init, move the high water mark computation intotcg_prologue_init.Reviewed-by Peter Maydell <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- tcg/tcg.c | 35 ++++++++++++++++++++++++++++------- translate-all.c | 28 +++++++++------------------- 2 files changed, 37 insertions(+), 26 deletions(-)Good idea to move it. I have done some experiments with putting slow path "helpers" in the prologue, and I ended-up going over the 1024 bytes limits.
Quoted 36 lines
tcg/tcg.c +23
-4@@ -363,17 +363,38 @@ void tcg_context_init(TCGContext *s)void tcg_prologue_init (TCGContext *s) { -/* init global prologue and epilogue */ - s->code_buf = s->code_gen_prologue; - s->code_ptr = s->code_buf; +size_t prologue_size, total_size; +void *buf0, *buf1; + +/* Put the prologue at the beginning of code_gen_buffer. */ + buf0 = s->code_gen_buffer; + s->code_ptr = buf0; + s->code_buf = buf0; + s->code_gen_prologue = buf0; + +/* Generate the prologue. */ tcg_target_qemu_prologue (s); -flush_icache_range ((uintptr_t )s->code_buf, (uintptr_t )s->code_ptr); + buf1 = s->code_ptr; +flush_icache_range ((uintptr_t )buf0, (uintptr_t )buf1); + +/* Deduct the prologue from the buffer. */ + prologue_size =tcg_current_code_size (s); + s->code_gen_ptr = buf1; + s->code_gen_buffer = buf1; + s->code_buf = buf1; + total_size = s->code_gen_buffer_size - prologue_size; + s->code_gen_buffer_size = total_size; + +/* Compute a high-water mark, at which we voluntarily flush the +buffer and start over. */
Quoted 8 lines
tcg/tcg.c void tcg_context_init(TCGContext *s) · line 392
Quoted 3 lines
tcg/tcg.c +3
-0+ s->code_gen_buffer_max_size = total_size -TCG_MAX_OP_SIZE *OPC_BUF_SIZE ; + +tcg_register_jit (s->code_gen_buffer, total_size);I am not sure why you moved this 2 lines there, I think they have more their place in
code_gen_alloc()so that the heuristics stay at the same place.total_sizeis available ins->code_gen_buffer_size, so that should be doable.
Because it was done too early for user-only. There, the sequence is
code_gen_alloc
place guest image, setting GUEST_BASE
tcg_prologue_init
We need the guest base for generating the prologue on most targets. Although clearly a better ordering is to place the guest image *first* before doing anything else. None of the other large allocations (including tbs) really care where they're placed.
Something to fix later, or should I do a v5?
r~