unicorn/qemu/include/exec
Sergey Fedorov ba9a237586
tcg: Rework tb_invalidated_flag
'tb_invalidated_flag' was meant to catch two events:
* some TB has been invalidated by tb_phys_invalidate();
* the whole translation buffer has been flushed by tb_flush().

Then it was checked:
* in cpu_exec() to ensure that the last executed TB can be safely
linked to directly call the next one;
* in cpu_exec_nocache() to decide if the original TB should be provided
for further possible invalidation along with the temporarily
generated TB.

It is always safe to patch an invalidated TB since it is not going to be
used anyway. It is also safe to call tb_phys_invalidate() for an already
invalidated TB. Thus, setting this flag in tb_phys_invalidate() is
simply unnecessary. Moreover, it can prevent from pretty proper linking
of TBs, if any arbitrary TB has been invalidated. So just don't touch it
in tb_phys_invalidate().

If this flag is only used to catch whether tb_flush() has been called
then rename it to 'tb_flushed'. Declare it as 'bool' and stick to using
only 'true' and 'false' to set its value. Also, instead of setting it in
tb_gen_code(), just after tb_flush() has been called, do it right inside
of tb_flush().

In cpu_exec(), this flag is used to track if tb_flush() has been called
and have made 'next_tb' (a reference to the last executed TB) invalid
for linking it to directly call the next TB. tb_flush() can be called
during the CPU execution loop from tb_gen_code(), during TB execution or
by another thread while 'tb_lock' is released. Catch for translation
buffer flush reliably by resetting this flag once before first TB lookup
and each time we find it set before trying to add a direct jump. Don't
touch in in tb_find_physical().

Each vCPU has its own execution loop in multithreaded mode and thus
should have its own copy of the flag to be able to reset it with its own
'next_tb' and don't affect any other vCPU execution thread. So make this
flag per-vCPU and move it to CPUState.

In cpu_exec_nocache(), we only need to check if tb_flush() has been
called from tb_gen_code() called by cpu_exec_nocache() itself. To do
this reliably, preserve the old value of the flag, reset it before
calling tb_gen_code(), check afterwards, and combine the saved value
back to the flag.

This patch is based on the patch "tcg: move tb_invalidated_flag to
CPUState" from Paolo Bonzini <pbonzini@redhat.com>.

Backports commit 6f789be56d3f38e9214dafcfab3bf9be7191f370 from qemu
2018-02-23 23:34:51 -05:00
..
address-spaces.h import 2015-08-21 15:04:50 +08:00
cpu_ldst_template.h softmmu: add helper function to pass through retaddr 2018-02-17 15:23:38 -05:00
cpu_ldst.h softmmu: remove now unused functions 2018-02-17 15:23:38 -05:00
cpu-all.h cpu-all: complete real host page size API 2018-02-17 15:23:16 -05:00
cpu-common.h qemu_ram_foreach_block: pass up error value, and down the ramblock name 2018-02-18 19:17:18 -05:00
cpu-defs.h cpu_defs: Simplify CPUTLB padding logic 2018-02-17 15:23:27 -05:00
cputlb.h include/exec: Move cputlb exec.c defs out 2018-02-23 10:52:25 -05:00
exec-all.h tcg: Rework tb_invalidated_flag 2018-02-23 23:34:51 -05:00
gen-icount.h gen-icount: Use tcg_set_insn_param 2018-02-23 20:01:17 -05:00
helper-gen.h import 2015-08-21 15:04:50 +08:00
helper-head.h import 2015-08-21 15:04:50 +08:00
helper-proto.h import 2015-08-21 15:04:50 +08:00
helper-tcg.h This code should now build the x86_x64-softmmu part 2. 2017-01-19 22:50:28 +11:00
hwaddr.h platform.h move #3 2017-01-21 00:13:21 +11:00
ioport.h import 2015-08-21 15:04:50 +08:00
memattrs.h target-i386: introduce cpu_get_mem_attrs 2018-02-13 11:33:39 -05:00
memory-internal.h import 2015-08-21 15:04:50 +08:00
memory.h Merge memory_region_init_reservation() into memory_region_init_io() 2018-02-21 11:23:00 -05:00
ram_addr.h memory: fix usage of find_next_bit and find_next_zero_bit 2018-02-22 19:51:43 -05:00
ramlist.h memory: RCU ram_list.dirty_memory[] for safe RAM hotplug 2018-02-22 15:38:03 -05:00
semihost.h exec: Add semihosting stubs 2018-02-17 15:23:33 -05:00
tb-hash.h cpu-defs: Move out TB_JMP defines 2018-02-17 15:23:15 -05:00