4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
22 #define NO_CPU_IO_DEFS
24 #include "disas/disas.h"
25 #include "exec/exec-all.h"
27 #if defined(CONFIG_USER_ONLY)
29 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
30 #include <sys/param.h>
31 #if __FreeBSD_version >= 700104
32 #define HAVE_KINFO_GETVMMAP
33 #define sigqueue sigqueue_freebsd /* avoid redefinition */
35 #include <machine/profile.h>
44 #include "exec/ram_addr.h"
47 #include "exec/cputlb.h"
48 #include "exec/translate-all.h"
49 #include "exec/translator.h"
50 #include "qemu/bitmap.h"
51 #include "qemu/qemu-print.h"
52 #include "qemu/main-loop.h"
53 #include "qemu/cacheinfo.h"
55 #include "sysemu/cpus.h"
56 #include "sysemu/cpu-timers.h"
57 #include "sysemu/tcg.h"
58 #include "qapi/error.h"
59 #include "hw/core/tcg-cpu-ops.h"
60 #include "tb-jmp-cache.h"
62 #include "tb-context.h"
66 /* Make sure all possible CPU event bits fit in tb->trace_vcpu_dstate */
67 QEMU_BUILD_BUG_ON(CPU_TRACE_DSTATE_MAX_EVENTS
>
68 sizeof_field(TranslationBlock
, trace_vcpu_dstate
)
73 /* Encode VAL as a signed leb128 sequence at P.
74 Return P incremented past the encoded value. */
75 static uint8_t *encode_sleb128(uint8_t *p
, target_long val
)
82 more
= !((val
== 0 && (byte
& 0x40) == 0)
83 || (val
== -1 && (byte
& 0x40) != 0));
93 /* Decode a signed leb128 sequence at *PP; increment *PP past the
94 decoded value. Return the decoded value. */
95 static target_long
decode_sleb128(const uint8_t **pp
)
97 const uint8_t *p
= *pp
;
103 val
|= (target_ulong
)(byte
& 0x7f) << shift
;
105 } while (byte
& 0x80);
106 if (shift
< TARGET_LONG_BITS
&& (byte
& 0x40)) {
107 val
|= -(target_ulong
)1 << shift
;
114 /* Encode the data collected about the instructions while compiling TB.
115 Place the data at BLOCK, and return the number of bytes consumed.
117 The logical table consists of TARGET_INSN_START_WORDS target_ulong's,
118 which come from the target's insn_start data, followed by a uintptr_t
119 which comes from the host pc of the end of the code implementing the insn.
121 Each line of the table is encoded as sleb128 deltas from the previous
122 line. The seed for the first line is { tb->pc, 0..., tb->tc.ptr }.
123 That is, the first column is seeded with the guest pc, the last column
124 with the host pc, and the middle columns with zeros. */
126 static int encode_search(TranslationBlock
*tb
, uint8_t *block
)
128 uint8_t *highwater
= tcg_ctx
->code_gen_highwater
;
132 for (i
= 0, n
= tb
->icount
; i
< n
; ++i
) {
135 for (j
= 0; j
< TARGET_INSN_START_WORDS
; ++j
) {
137 prev
= (!(tb_cflags(tb
) & CF_PCREL
) && j
== 0 ? tb
->pc
: 0);
139 prev
= tcg_ctx
->gen_insn_data
[i
- 1][j
];
141 p
= encode_sleb128(p
, tcg_ctx
->gen_insn_data
[i
][j
] - prev
);
143 prev
= (i
== 0 ? 0 : tcg_ctx
->gen_insn_end_off
[i
- 1]);
144 p
= encode_sleb128(p
, tcg_ctx
->gen_insn_end_off
[i
] - prev
);
146 /* Test for (pending) buffer overflow. The assumption is that any
147 one row beginning below the high water mark cannot overrun
148 the buffer completely. Thus we can test for overflow after
149 encoding a row without having to check during encoding. */
150 if (unlikely(p
> highwater
)) {
158 static int cpu_unwind_data_from_tb(TranslationBlock
*tb
, uintptr_t host_pc
,
161 uintptr_t iter_pc
= (uintptr_t)tb
->tc
.ptr
;
162 const uint8_t *p
= tb
->tc
.ptr
+ tb
->tc
.size
;
163 int i
, j
, num_insns
= tb
->icount
;
165 host_pc
-= GETPC_ADJ
;
167 if (host_pc
< iter_pc
) {
171 memset(data
, 0, sizeof(uint64_t) * TARGET_INSN_START_WORDS
);
172 if (!(tb_cflags(tb
) & CF_PCREL
)) {
177 * Reconstruct the stored insn data while looking for the point
178 * at which the end of the insn exceeds host_pc.
180 for (i
= 0; i
< num_insns
; ++i
) {
181 for (j
= 0; j
< TARGET_INSN_START_WORDS
; ++j
) {
182 data
[j
] += decode_sleb128(&p
);
184 iter_pc
+= decode_sleb128(&p
);
185 if (iter_pc
> host_pc
) {
186 return num_insns
- i
;
193 * The cpu state corresponding to 'host_pc' is restored in
194 * preparation for exiting the TB.
196 void cpu_restore_state_from_tb(CPUState
*cpu
, TranslationBlock
*tb
,
199 uint64_t data
[TARGET_INSN_START_WORDS
];
200 #ifdef CONFIG_PROFILER
201 TCGProfile
*prof
= &tcg_ctx
->prof
;
202 int64_t ti
= profile_getclock();
204 int insns_left
= cpu_unwind_data_from_tb(tb
, host_pc
, data
);
206 if (insns_left
< 0) {
210 if (tb_cflags(tb
) & CF_USE_ICOUNT
) {
211 assert(icount_enabled());
213 * Reset the cycle counter to the start of the block and
214 * shift if to the number of actually executed instructions.
216 cpu_neg(cpu
)->icount_decr
.u16
.low
+= insns_left
;
219 cpu
->cc
->tcg_ops
->restore_state_to_opc(cpu
, tb
, data
);
221 #ifdef CONFIG_PROFILER
222 qatomic_set(&prof
->restore_time
,
223 prof
->restore_time
+ profile_getclock() - ti
);
224 qatomic_set(&prof
->restore_count
, prof
->restore_count
+ 1);
228 bool cpu_restore_state(CPUState
*cpu
, uintptr_t host_pc
)
231 * The host_pc has to be in the rx region of the code buffer.
232 * If it is not we will not be able to resolve it here.
233 * The two cases where host_pc will not be correct are:
235 * - fault during translation (instruction fetch)
236 * - fault from helper (not using GETPC() macro)
238 * Either way we need return early as we can't resolve it here.
240 if (in_code_gen_buffer((const void *)(host_pc
- tcg_splitwx_diff
))) {
241 TranslationBlock
*tb
= tcg_tb_lookup(host_pc
);
243 cpu_restore_state_from_tb(cpu
, tb
, host_pc
);
250 bool cpu_unwind_state_data(CPUState
*cpu
, uintptr_t host_pc
, uint64_t *data
)
252 if (in_code_gen_buffer((const void *)(host_pc
- tcg_splitwx_diff
))) {
253 TranslationBlock
*tb
= tcg_tb_lookup(host_pc
);
255 return cpu_unwind_data_from_tb(tb
, host_pc
, data
) >= 0;
264 page_table_config_init();
268 * Isolate the portion of code gen which can setjmp/longjmp.
269 * Return the size of the generated code, or negative on error.
271 static int setjmp_gen_code(CPUArchState
*env
, TranslationBlock
*tb
,
272 target_ulong pc
, void *host_pc
,
273 int *max_insns
, int64_t *ti
)
275 int ret
= sigsetjmp(tcg_ctx
->jmp_trans
, 0);
276 if (unlikely(ret
!= 0)) {
280 tcg_func_start(tcg_ctx
);
282 tcg_ctx
->cpu
= env_cpu(env
);
283 gen_intermediate_code(env_cpu(env
), tb
, max_insns
, pc
, host_pc
);
284 assert(tb
->size
!= 0);
286 *max_insns
= tb
->icount
;
288 #ifdef CONFIG_PROFILER
289 qatomic_set(&tcg_ctx
->prof
.tb_count
, tcg_ctx
->prof
.tb_count
+ 1);
290 qatomic_set(&tcg_ctx
->prof
.interm_time
,
291 tcg_ctx
->prof
.interm_time
+ profile_getclock() - *ti
);
292 *ti
= profile_getclock();
295 return tcg_gen_code(tcg_ctx
, tb
, pc
);
298 /* Called with mmap_lock held for user mode emulation. */
299 TranslationBlock
*tb_gen_code(CPUState
*cpu
,
300 target_ulong pc
, target_ulong cs_base
,
301 uint32_t flags
, int cflags
)
303 CPUArchState
*env
= cpu
->env_ptr
;
304 TranslationBlock
*tb
, *existing_tb
;
305 tb_page_addr_t phys_pc
;
306 tcg_insn_unit
*gen_code_buf
;
307 int gen_code_size
, search_size
, max_insns
;
308 #ifdef CONFIG_PROFILER
309 TCGProfile
*prof
= &tcg_ctx
->prof
;
314 assert_memory_lock();
315 qemu_thread_jit_write();
317 phys_pc
= get_page_addr_code_hostp(env
, pc
, &host_pc
);
320 /* Generate a one-shot TB with 1 insn in it */
321 cflags
= (cflags
& ~CF_COUNT_MASK
) | CF_LAST_IO
| 1;
324 max_insns
= cflags
& CF_COUNT_MASK
;
325 if (max_insns
== 0) {
326 max_insns
= TCG_MAX_INSNS
;
328 QEMU_BUILD_BUG_ON(CF_COUNT_MASK
+ 1 != TCG_MAX_INSNS
);
331 tb
= tcg_tb_alloc(tcg_ctx
);
333 /* flush must be done */
336 /* Make the execution loop process the flush as soon as possible. */
337 cpu
->exception_index
= EXCP_INTERRUPT
;
341 gen_code_buf
= tcg_ctx
->code_gen_ptr
;
342 tb
->tc
.ptr
= tcg_splitwx_to_rx(gen_code_buf
);
343 if (!(cflags
& CF_PCREL
)) {
346 tb
->cs_base
= cs_base
;
349 tb
->trace_vcpu_dstate
= *cpu
->trace_dstate
;
350 tb_set_page_addr0(tb
, phys_pc
);
351 tb_set_page_addr1(tb
, -1);
352 tcg_ctx
->gen_tb
= tb
;
355 #ifdef CONFIG_PROFILER
356 /* includes aborted translations because of exceptions */
357 qatomic_set(&prof
->tb_count1
, prof
->tb_count1
+ 1);
358 ti
= profile_getclock();
361 trace_translate_block(tb
, pc
, tb
->tc
.ptr
);
363 gen_code_size
= setjmp_gen_code(env
, tb
, pc
, host_pc
, &max_insns
, &ti
);
364 if (unlikely(gen_code_size
< 0)) {
365 switch (gen_code_size
) {
368 * Overflow of code_gen_buffer, or the current slice of it.
370 * TODO: We don't need to re-do gen_intermediate_code, nor
371 * should we re-do the tcg optimization currently hidden
372 * inside tcg_gen_code. All that should be required is to
373 * flush the TBs, allocate a new TB, re-initialize it per
374 * above, and re-do the actual code generation.
376 qemu_log_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
,
377 "Restarting code generation for "
378 "code_gen_buffer overflow\n");
379 goto buffer_overflow
;
383 * The code generated for the TranslationBlock is too large.
384 * The maximum size allowed by the unwind info is 64k.
385 * There may be stricter constraints from relocations
386 * in the tcg backend.
388 * Try again with half as many insns as we attempted this time.
389 * If a single insn overflows, there's a bug somewhere...
391 assert(max_insns
> 1);
393 qemu_log_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
,
394 "Restarting code generation with "
395 "smaller translation block (max %d insns)\n",
400 g_assert_not_reached();
403 search_size
= encode_search(tb
, (void *)gen_code_buf
+ gen_code_size
);
404 if (unlikely(search_size
< 0)) {
405 goto buffer_overflow
;
407 tb
->tc
.size
= gen_code_size
;
410 * For CF_PCREL, attribute all executions of the generated code
411 * to its first mapping.
413 perf_report_code(pc
, tb
, tcg_splitwx_to_rx(gen_code_buf
));
415 #ifdef CONFIG_PROFILER
416 qatomic_set(&prof
->code_time
, prof
->code_time
+ profile_getclock() - ti
);
417 qatomic_set(&prof
->code_in_len
, prof
->code_in_len
+ tb
->size
);
418 qatomic_set(&prof
->code_out_len
, prof
->code_out_len
+ gen_code_size
);
419 qatomic_set(&prof
->search_out_len
, prof
->search_out_len
+ search_size
);
423 if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM
) &&
424 qemu_log_in_addr_range(pc
)) {
425 FILE *logfile
= qemu_log_trylock();
427 int code_size
, data_size
;
428 const tcg_target_ulong
*rx_data_gen_ptr
;
432 if (tcg_ctx
->data_gen_ptr
) {
433 rx_data_gen_ptr
= tcg_splitwx_to_rx(tcg_ctx
->data_gen_ptr
);
434 code_size
= (const void *)rx_data_gen_ptr
- tb
->tc
.ptr
;
435 data_size
= gen_code_size
- code_size
;
438 code_size
= gen_code_size
;
442 /* Dump header and the first instruction */
443 fprintf(logfile
, "OUT: [size=%d]\n", gen_code_size
);
445 " -- guest addr 0x" TARGET_FMT_lx
" + tb prologue\n",
446 tcg_ctx
->gen_insn_data
[insn
][0]);
447 chunk_start
= tcg_ctx
->gen_insn_end_off
[insn
];
448 disas(logfile
, tb
->tc
.ptr
, chunk_start
);
451 * Dump each instruction chunk, wrapping up empty chunks into
452 * the next instruction. The whole array is offset so the
453 * first entry is the beginning of the 2nd instruction.
455 while (insn
< tb
->icount
) {
456 size_t chunk_end
= tcg_ctx
->gen_insn_end_off
[insn
];
457 if (chunk_end
> chunk_start
) {
458 fprintf(logfile
, " -- guest addr 0x" TARGET_FMT_lx
"\n",
459 tcg_ctx
->gen_insn_data
[insn
][0]);
460 disas(logfile
, tb
->tc
.ptr
+ chunk_start
,
461 chunk_end
- chunk_start
);
462 chunk_start
= chunk_end
;
467 if (chunk_start
< code_size
) {
468 fprintf(logfile
, " -- tb slow paths + alignment\n");
469 disas(logfile
, tb
->tc
.ptr
+ chunk_start
,
470 code_size
- chunk_start
);
473 /* Finally dump any data we may have after the block */
476 fprintf(logfile
, " data: [size=%d]\n", data_size
);
477 for (i
= 0; i
< data_size
/ sizeof(tcg_target_ulong
); i
++) {
478 if (sizeof(tcg_target_ulong
) == 8) {
480 "0x%08" PRIxPTR
": .quad 0x%016" TCG_PRIlx
"\n",
481 (uintptr_t)&rx_data_gen_ptr
[i
], rx_data_gen_ptr
[i
]);
482 } else if (sizeof(tcg_target_ulong
) == 4) {
484 "0x%08" PRIxPTR
": .long 0x%08" TCG_PRIlx
"\n",
485 (uintptr_t)&rx_data_gen_ptr
[i
], rx_data_gen_ptr
[i
]);
487 qemu_build_not_reached();
491 fprintf(logfile
, "\n");
492 qemu_log_unlock(logfile
);
497 qatomic_set(&tcg_ctx
->code_gen_ptr
, (void *)
498 ROUND_UP((uintptr_t)gen_code_buf
+ gen_code_size
+ search_size
,
502 qemu_spin_init(&tb
->jmp_lock
);
503 tb
->jmp_list_head
= (uintptr_t)NULL
;
504 tb
->jmp_list_next
[0] = (uintptr_t)NULL
;
505 tb
->jmp_list_next
[1] = (uintptr_t)NULL
;
506 tb
->jmp_dest
[0] = (uintptr_t)NULL
;
507 tb
->jmp_dest
[1] = (uintptr_t)NULL
;
509 /* init original jump addresses which have been set during tcg_gen_code() */
510 if (tb
->jmp_reset_offset
[0] != TB_JMP_OFFSET_INVALID
) {
511 tb_reset_jump(tb
, 0);
513 if (tb
->jmp_reset_offset
[1] != TB_JMP_OFFSET_INVALID
) {
514 tb_reset_jump(tb
, 1);
518 * If the TB is not associated with a physical RAM page then it must be
519 * a temporary one-insn TB, and we have nothing left to do. Return early
520 * before attempting to link to other TBs or add to the lookup table.
522 if (tb_page_addr0(tb
) == -1) {
527 * Insert TB into the corresponding region tree before publishing it
528 * through QHT. Otherwise rewinding happened in the TB might fail to
529 * lookup itself using host PC.
534 * No explicit memory barrier is required -- tb_link_page() makes the
535 * TB visible in a consistent state.
537 existing_tb
= tb_link_page(tb
, tb_page_addr0(tb
), tb_page_addr1(tb
));
538 /* if the TB already exists, discard what we just translated */
539 if (unlikely(existing_tb
!= tb
)) {
540 uintptr_t orig_aligned
= (uintptr_t)gen_code_buf
;
542 orig_aligned
-= ROUND_UP(sizeof(*tb
), qemu_icache_linesize
);
543 qatomic_set(&tcg_ctx
->code_gen_ptr
, (void *)orig_aligned
);
550 /* user-mode: call with mmap_lock held */
551 void tb_check_watchpoint(CPUState
*cpu
, uintptr_t retaddr
)
553 TranslationBlock
*tb
;
555 assert_memory_lock();
557 tb
= tcg_tb_lookup(retaddr
);
559 /* We can use retranslation to find the PC. */
560 cpu_restore_state_from_tb(cpu
, tb
, retaddr
);
561 tb_phys_invalidate(tb
, -1);
563 /* The exception probably happened in a helper. The CPU state should
564 have been saved before calling it. Fetch the PC from there. */
565 CPUArchState
*env
= cpu
->env_ptr
;
566 target_ulong pc
, cs_base
;
570 cpu_get_tb_cpu_state(env
, &pc
, &cs_base
, &flags
);
571 addr
= get_page_addr_code(env
, pc
);
573 tb_invalidate_phys_range(addr
, addr
+ 1);
578 #ifndef CONFIG_USER_ONLY
580 * In deterministic execution mode, instructions doing device I/Os
581 * must be at the end of the TB.
583 * Called by softmmu_template.h, with iothread mutex not held.
585 void cpu_io_recompile(CPUState
*cpu
, uintptr_t retaddr
)
587 TranslationBlock
*tb
;
591 tb
= tcg_tb_lookup(retaddr
);
593 cpu_abort(cpu
, "cpu_io_recompile: could not find TB for pc=%p",
596 cpu_restore_state_from_tb(cpu
, tb
, retaddr
);
599 * Some guests must re-execute the branch when re-executing a delay
600 * slot instruction. When this is the case, adjust icount and N
601 * to account for the re-execution of the branch.
604 cc
= CPU_GET_CLASS(cpu
);
605 if (cc
->tcg_ops
->io_recompile_replay_branch
&&
606 cc
->tcg_ops
->io_recompile_replay_branch(cpu
, tb
)) {
607 cpu_neg(cpu
)->icount_decr
.u16
.low
++;
612 * Exit the loop and potentially generate a new TB executing the
613 * just the I/O insns. We also limit instrumentation to memory
614 * operations only (which execute after completion) so we don't
615 * double instrument the instruction.
617 cpu
->cflags_next_tb
= curr_cflags(cpu
) | CF_MEMI_ONLY
| CF_LAST_IO
| n
;
619 if (qemu_loglevel_mask(CPU_LOG_EXEC
)) {
620 target_ulong pc
= log_pc(cpu
, tb
);
621 if (qemu_log_in_addr_range(pc
)) {
622 qemu_log("cpu_io_recompile: rewound execution of TB to "
623 TARGET_FMT_lx
"\n", pc
);
627 cpu_loop_exit_noexc(cpu
);
630 static void print_qht_statistics(struct qht_stats hst
, GString
*buf
)
636 if (!hst
.head_buckets
) {
639 g_string_append_printf(buf
, "TB hash buckets %zu/%zu "
640 "(%0.2f%% head buckets used)\n",
641 hst
.used_head_buckets
, hst
.head_buckets
,
642 (double)hst
.used_head_buckets
/
643 hst
.head_buckets
* 100);
645 hgram_opts
= QDIST_PR_BORDER
| QDIST_PR_LABELS
;
646 hgram_opts
|= QDIST_PR_100X
| QDIST_PR_PERCENT
;
647 if (qdist_xmax(&hst
.occupancy
) - qdist_xmin(&hst
.occupancy
) == 1) {
648 hgram_opts
|= QDIST_PR_NODECIMAL
;
650 hgram
= qdist_pr(&hst
.occupancy
, 10, hgram_opts
);
651 g_string_append_printf(buf
, "TB hash occupancy %0.2f%% avg chain occ. "
653 qdist_avg(&hst
.occupancy
) * 100, hgram
);
656 hgram_opts
= QDIST_PR_BORDER
| QDIST_PR_LABELS
;
657 hgram_bins
= qdist_xmax(&hst
.chain
) - qdist_xmin(&hst
.chain
);
658 if (hgram_bins
> 10) {
662 hgram_opts
|= QDIST_PR_NODECIMAL
| QDIST_PR_NOBINRANGE
;
664 hgram
= qdist_pr(&hst
.chain
, hgram_bins
, hgram_opts
);
665 g_string_append_printf(buf
, "TB hash avg chain %0.3f buckets. "
667 qdist_avg(&hst
.chain
), hgram
);
671 struct tb_tree_stats
{
675 size_t max_target_size
;
676 size_t direct_jmp_count
;
677 size_t direct_jmp2_count
;
681 static gboolean
tb_tree_stats_iter(gpointer key
, gpointer value
, gpointer data
)
683 const TranslationBlock
*tb
= value
;
684 struct tb_tree_stats
*tst
= data
;
687 tst
->host_size
+= tb
->tc
.size
;
688 tst
->target_size
+= tb
->size
;
689 if (tb
->size
> tst
->max_target_size
) {
690 tst
->max_target_size
= tb
->size
;
692 if (tb_page_addr1(tb
) != -1) {
695 if (tb
->jmp_reset_offset
[0] != TB_JMP_OFFSET_INVALID
) {
696 tst
->direct_jmp_count
++;
697 if (tb
->jmp_reset_offset
[1] != TB_JMP_OFFSET_INVALID
) {
698 tst
->direct_jmp2_count
++;
704 void dump_exec_info(GString
*buf
)
706 struct tb_tree_stats tst
= {};
707 struct qht_stats hst
;
708 size_t nb_tbs
, flush_full
, flush_part
, flush_elide
;
710 tcg_tb_foreach(tb_tree_stats_iter
, &tst
);
712 /* XXX: avoid using doubles ? */
713 g_string_append_printf(buf
, "Translation buffer state:\n");
715 * Report total code size including the padding and TB structs;
716 * otherwise users might think "-accel tcg,tb-size" is not honoured.
717 * For avg host size we use the precise numbers from tb_tree_stats though.
719 g_string_append_printf(buf
, "gen code size %zu/%zu\n",
720 tcg_code_size(), tcg_code_capacity());
721 g_string_append_printf(buf
, "TB count %zu\n", nb_tbs
);
722 g_string_append_printf(buf
, "TB avg target size %zu max=%zu bytes\n",
723 nb_tbs
? tst
.target_size
/ nb_tbs
: 0,
724 tst
.max_target_size
);
725 g_string_append_printf(buf
, "TB avg host size %zu bytes "
726 "(expansion ratio: %0.1f)\n",
727 nb_tbs
? tst
.host_size
/ nb_tbs
: 0,
729 (double)tst
.host_size
/ tst
.target_size
: 0);
730 g_string_append_printf(buf
, "cross page TB count %zu (%zu%%)\n",
732 nb_tbs
? (tst
.cross_page
* 100) / nb_tbs
: 0);
733 g_string_append_printf(buf
, "direct jump count %zu (%zu%%) "
734 "(2 jumps=%zu %zu%%)\n",
735 tst
.direct_jmp_count
,
736 nb_tbs
? (tst
.direct_jmp_count
* 100) / nb_tbs
: 0,
737 tst
.direct_jmp2_count
,
738 nb_tbs
? (tst
.direct_jmp2_count
* 100) / nb_tbs
: 0);
740 qht_statistics_init(&tb_ctx
.htable
, &hst
);
741 print_qht_statistics(hst
, buf
);
742 qht_statistics_destroy(&hst
);
744 g_string_append_printf(buf
, "\nStatistics:\n");
745 g_string_append_printf(buf
, "TB flush count %u\n",
746 qatomic_read(&tb_ctx
.tb_flush_count
));
747 g_string_append_printf(buf
, "TB invalidate count %u\n",
748 qatomic_read(&tb_ctx
.tb_phys_invalidate_count
));
750 tlb_flush_counts(&flush_full
, &flush_part
, &flush_elide
);
751 g_string_append_printf(buf
, "TLB full flushes %zu\n", flush_full
);
752 g_string_append_printf(buf
, "TLB partial flushes %zu\n", flush_part
);
753 g_string_append_printf(buf
, "TLB elided flushes %zu\n", flush_elide
);
757 #else /* CONFIG_USER_ONLY */
759 void cpu_interrupt(CPUState
*cpu
, int mask
)
761 g_assert(qemu_mutex_iothread_locked());
762 cpu
->interrupt_request
|= mask
;
763 qatomic_set(&cpu_neg(cpu
)->icount_decr
.u16
.high
, -1);
766 #endif /* CONFIG_USER_ONLY */
769 * Called by generic code at e.g. cpu reset after cpu creation,
770 * therefore we must be prepared to allocate the jump cache.
772 void tcg_flush_jmp_cache(CPUState
*cpu
)
774 CPUJumpCache
*jc
= cpu
->tb_jmp_cache
;
776 /* During early initialization, the cache may not yet be allocated. */
777 if (unlikely(jc
== NULL
)) {
781 for (int i
= 0; i
< TB_JMP_CACHE_SIZE
; i
++) {
782 qatomic_set(&jc
->array
[i
].tb
, NULL
);
786 /* This is a wrapper for common code that can not use CONFIG_SOFTMMU */
787 void tcg_flush_softmmu_tlb(CPUState
*cs
)
789 #ifdef CONFIG_SOFTMMU