unicorn/qemu
Emilio G. Cota 23a55a277f
tcg: enable multiple TCG contexts in softmmu
This enables parallel TCG code generation. However, we do not take
advantage of it yet since tb_lock is still held during tb_gen_code.

In user-mode we use a single TCG context; see the documentation
added to tcg_region_init for the rationale.

Note that targets do not need any conversion: targets initialize a
TCGContext (e.g. defining TCG globals), and after this initialization
has finished, the context is cloned by the vCPU threads, each of
them keeping a separate copy.

TCG threads claim one entry in tcg_ctxs[] by atomically increasing
n_tcg_ctxs. Do not be too annoyed by the subsequent atomic_read's
of that variable and tcg_ctxs; they are there just to play nice with
analysis tools such as thread sanitizer.

Note that we do not allocate an array of contexts (we allocate
an array of pointers instead) because when tcg_context_init
is called, we do not know yet how many contexts we'll use since
the bool behind qemu_tcg_mttcg_enabled() isn't set yet.

Previous patches folded some TCG globals into TCGContext. The non-const
globals remaining are only set at init time, i.e. before the TCG
threads are spawned. Here is a list of these set-at-init-time globals
under tcg/:

Only written by tcg_context_init:
- indirect_reg_alloc_order
- tcg_op_defs
Only written by tcg_target_init (called from tcg_context_init):
- tcg_target_available_regs
- tcg_target_call_clobber_regs
- arm: arm_arch, use_idiv_instructions
- i386: have_cmov, have_bmi1, have_bmi2, have_lzcnt,
have_movbe, have_popcnt
- mips: use_movnz_instructions, use_mips32_instructions,
use_mips32r2_instructions, got_sigill (tcg_target_detect_isa)
- ppc: have_isa_2_06, have_isa_3_00, tb_ret_addr
- s390: tb_ret_addr, s390_facilities
- sparc: qemu_ld_trampoline, qemu_st_trampoline (build_trampolines),
use_vis3_instructions

Only written by tcg_prologue_init:
- 'struct jit_code_entry one_entry'
- aarch64: tb_ret_addr
- arm: tb_ret_addr
- i386: tb_ret_addr, guest_base_flags
- ia64: tb_ret_addr
- mips: tb_ret_addr, bswap32_addr, bswap32u_addr, bswap64_addr

Backports commit 3468b59e18b179bc63c7ce934de912dfa9596122 from qemu
2018-03-14 14:32:34 -04:00
..
accel tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
crypto crypto: Clean up includes 2018-02-19 00:47:40 -05:00
default-configs arm64eb: add support for ARM64 big endian. 2017-04-24 23:30:01 +08:00
docs docs: clarify memory region lifecycle 2018-02-12 15:11:21 -05:00
fpu softfloat: fix crash on int conversion of SNaN 2018-03-09 11:40:17 -05:00
hw target/arm: Make 'any' CPU just an alias for 'max' 2018-03-12 10:11:49 -04:00
include cpu: Unicorn-ify the qemu_tcg_mttcg_enabled() macro 2018-03-14 12:10:29 -04:00
qapi qapi: Move qapi-schema.json to qapi/, rename generated files 2018-03-09 11:35:11 -05:00
qobject qdict: Introduce qdict_rename_keys() 2018-03-12 10:11:48 -04:00
qom tcg: Add CPUState cflags_next_tb 2018-03-13 14:39:43 -04:00
scripts qapi: Move qapi-schema.json to qapi/, rename generated files 2018-03-09 11:35:11 -05:00
target tcg: take tb_ctx out of TCGContext 2018-03-14 09:18:12 -04:00
tcg tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
util osdep: introduce qemu_mprotect_rwx/none 2018-03-14 12:10:28 -04:00
aarch64.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
aarch64eb.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
accel.c clean-up: removed duplicate #includes 2018-02-28 08:51:56 -05:00
arm.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
armeb.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
CODING_STYLE import 2015-08-21 15:04:50 +08:00
configure tcg: move tcg backend files into accel/tcg/ 2018-03-13 11:48:15 -04:00
COPYING import 2015-08-21 15:04:50 +08:00
COPYING.LIB import 2015-08-21 15:04:50 +08:00
cpus.c tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
exec.c exec: Drop unnecessary code for unicorn 2018-03-12 10:11:46 -04:00
gen_all_header.sh arm64eb: add support for ARM64 big endian. 2017-04-24 23:30:01 +08:00
glib_compat.c translate-all: use a binary search tree to track TBs in TBContext 2018-03-13 16:18:29 -04:00
HACKING import 2015-08-21 15:04:50 +08:00
header_gen.py tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
ioport.c hw: remove pio_addr_t 2018-02-24 02:43:16 -05:00
LICENSE import 2015-08-21 15:04:50 +08:00
m68k.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
Makefile qapi: Don't create useless directory qapi-generated 2018-03-09 11:36:49 -05:00
Makefile.objs qapi: Move qapi-schema.json to qapi/, rename generated files 2018-03-09 11:35:11 -05:00
Makefile.target tcg: move tcg backend files into accel/tcg/ 2018-03-13 11:48:15 -04:00
memory.c memory: Share special empty FlatView 2018-03-11 22:34:28 -04:00
memory_ldst.inc.c exec: Drop unnecessary code for unicorn 2018-03-12 10:11:46 -04:00
memory_mapping.c include/qemu/osdep.h: Don't include qapi/error.h 2018-02-21 23:08:18 -05:00
mips.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
mips64.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
mips64el.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
mipsel.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
powerpc.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
qemu-timer.c timer/cpus: fix some typos and update some comments 2018-02-25 23:21:57 -05:00
rules.mak build-sys: silence make by default or V=0 2018-03-06 08:58:03 -05:00
sparc.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
sparc64.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
unicorn_common.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00
VERSION import 2015-08-21 15:04:50 +08:00
vl.c machine: Eliminate QEMUMachine and qemu_register_machine() 2018-03-11 15:22:25 -04:00
vl.h import 2015-08-21 15:04:50 +08:00
x86_64.h tcg: enable multiple TCG contexts in softmmu 2018-03-14 14:32:34 -04:00