Skip to content

Commit

Permalink
TCTI: add TCTI TCG backend for acceleration on non-JIT AArch64
Browse files Browse the repository at this point in the history
  • Loading branch information
ktemkin authored and osy committed Apr 29, 2021
1 parent a833a4b commit 376dc65
Show file tree
Hide file tree
Showing 16 changed files with 3,476 additions and 26 deletions.
6 changes: 3 additions & 3 deletions accel/tcg/translate-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ static bool alloc_code_gen_buffer_anon(size_t size, int prot,
return true;
}

#ifndef CONFIG_TCG_INTERPRETER
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
#ifdef CONFIG_POSIX
#include "qemu/memfd.h"

Expand Down Expand Up @@ -1256,7 +1256,7 @@ static bool alloc_code_gen_buffer_splitwx_vmremap(size_t size, Error **errp)

static bool alloc_code_gen_buffer_splitwx(size_t size, Error **errp)
{
#ifndef CONFIG_TCG_INTERPRETER
#if !defined(CONFIG_TCG_INTERPRETER) && !defined(CONFIG_TCG_THREADED_INTERPRETER)
# ifdef CONFIG_DARWIN
return alloc_code_gen_buffer_splitwx_vmremap(size, errp);
# endif
Expand Down Expand Up @@ -1289,7 +1289,7 @@ static bool alloc_code_gen_buffer(size_t size, int splitwx, Error **errp)

prot = PROT_READ | PROT_WRITE | PROT_EXEC;
flags = MAP_PRIVATE | MAP_ANONYMOUS;
#ifdef CONFIG_TCG_INTERPRETER
#if defined(CONFIG_TCG_INTERPRETER) || defined(CONFIG_TCG_THREADED_INTERPRETER)
/* The tcg interpreter does not need execute permission. */
prot = PROT_READ | PROT_WRITE;
#elif defined(CONFIG_DARWIN)
Expand Down
10 changes: 7 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ tsan="no"
fortify_source="$default_feature"
strip_opt="yes"
tcg_interpreter="false"
tcg_threaded_interpreter="false"
bigendian="no"
mingw32="no"
gcov="no"
Expand Down Expand Up @@ -1115,6 +1116,10 @@ for opt do
;;
--enable-tcg-interpreter) tcg_interpreter="true"
;;
--disable-tcg-tcti) tcg_threaded_interpreter="false"
;;
--enable-tcg-tcti) tcg_threaded_interpreter="true"
;;
--disable-cap-ng) cap_ng="disabled"
;;
--enable-cap-ng) cap_ng="enabled"
Expand Down Expand Up @@ -6469,9 +6474,8 @@ NINJA=$ninja $meson setup \
-Dvhost_user_blk_server=$vhost_user_blk_server -Dmultiprocess=$multiprocess \
-Dfuse=$fuse -Dfuse_lseek=$fuse_lseek -Dguest_agent_msi=$guest_agent_msi \
$(if test "$default_features" = no; then echo "-Dauto_features=disabled"; fi) \
-Dtcg_interpreter=$tcg_interpreter -Dshared_lib=$shared_lib \
$cross_arg \
"$PWD" "$source_path"
-Dtcg_interpreter=$tcg_interpreter -Dtcg_threaded_interpreter=$tcg_threaded_interpreter\
-Dshared_lib=$shared_lib $cross_arg "$PWD" "$source_path"

if test "$?" -ne 0 ; then
error_exit "meson setup failed"
Expand Down
2 changes: 2 additions & 0 deletions disas.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ static void initialize_debug_host(CPUDebug *s)
#endif
#if defined(CONFIG_TCG_INTERPRETER)
s->info.print_insn = print_insn_tci;
#elif defined(CONFIG_TCG_THREADED_INTERPRETER)
s->info.print_insn = print_insn_tcti;
#elif defined(__i386__)
s->info.mach = bfd_mach_i386_i386;
s->info.print_insn = print_insn_i386;
Expand Down
1 change: 1 addition & 0 deletions include/disas/dis-asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ typedef struct disassemble_info {
typedef int (*disassembler_ftype) (bfd_vma, disassemble_info *);

int print_insn_tci(bfd_vma, disassemble_info*);
int print_insn_tcti(bfd_vma, disassemble_info*);
int print_insn_big_mips (bfd_vma, disassemble_info*);
int print_insn_little_mips (bfd_vma, disassemble_info*);
int print_insn_nanomips (bfd_vma, disassemble_info*);
Expand Down
4 changes: 4 additions & 0 deletions include/exec/exec-all.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,11 @@ void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr);
#if defined(CONFIG_TCG_INTERPRETER)
extern __thread uintptr_t tci_tb_ptr;
# define GETPC() tci_tb_ptr
#elif defined(CONFIG_TCG_THREADED_INTERPRETER)
extern __thread uintptr_t tcti_call_return_address;
# define GETPC() tcti_call_return_address
#else
/* Note that this is correct for TCTI also; whose gadget behaves like native code. */
# define GETPC() \
((uintptr_t)__builtin_extract_return_addr(__builtin_return_address(0)))
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/tcg/tcg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ static inline unsigned get_mmuidx(TCGMemOpIdx oi)
#define TB_EXIT_IDXMAX 1
#define TB_EXIT_REQUESTED 3

#ifdef CONFIG_TCG_INTERPRETER
#if defined(CONFIG_TCG_INTERPRETER) || defined(CONFIG_TCG_THREADED_INTERPRETER)
uintptr_t tcg_qemu_tb_exec(CPUArchState *env, const void *tb_ptr);
#else
typedef uintptr_t tcg_prologue_fn(CPUArchState *env, const void *tb_ptr);
Expand Down
24 changes: 24 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ python = import('python').find_installation()
supported_oses = ['windows', 'freebsd', 'netbsd', 'openbsd', 'darwin', 'sunos', 'linux']
supported_cpus = ['ppc', 'ppc64', 's390x', 'riscv32', 'riscv64', 'x86', 'x86_64',
'arm', 'aarch64', 'mips', 'mips64', 'sparc', 'sparc64']
tcti_supported_cpus = ['aarch64']

cpu = host_machine.cpu_family()
targetos = host_machine.system()
Expand Down Expand Up @@ -248,6 +249,25 @@ if not get_option('tcg').disabled()
endif
if get_option('tcg_interpreter')
tcg_arch = 'tci'
elif get_option('tcg_threaded_interpreter')
if cpu not in tcti_supported_cpus
error('Unsupported CPU @0@ for TCTI, try --enable-tcg-interpreter'.format(cpu))
else
warning('TCTI is extremely experimental and incomplete! Things might break!')
tcg_arch = '@0@-tcti'.format(cpu)
endif

# Tell our compiler how to generate our TCTI gadgets.
gadget_generator = 'tcg/@0@/tcti-gadget-gen.py'.format(tcg_arch)
tcti_gadgets = custom_target('tcti-gadgets.c.inc',
output: 'tcti-gadgets.c.inc',
input: gadget_generator,
command: [find_program(gadget_generator), '@OUTPUT@'],
build_by_default: true,
build_always_stale: false)

genh += tcti_gadgets

elif config_host['ARCH'] == 'sparc64'
tcg_arch = 'sparc'
elif config_host['ARCH'] == 's390x'
Expand Down Expand Up @@ -1284,6 +1304,8 @@ foreach target : target_dirs
config_all += { sym: 'y' }
if sym == 'CONFIG_TCG' and tcg_arch == 'tci'
config_target += { 'CONFIG_TCG_INTERPRETER': 'y' }
elif sym == 'CONFIG_TCG' and tcg_arch.endswith('tcti')
config_target += { 'CONFIG_TCG_THREADED_INTERPRETER': 'y' }
elif sym == 'CONFIG_XEN' and have_xen_pci_passthrough
config_target += { 'CONFIG_XEN_PCI_PASSTHROUGH': 'y' }
endif
Expand Down Expand Up @@ -2575,6 +2597,8 @@ summary_info += {'TCG support': config_all.has_key('CONFIG_TCG')}
if config_all.has_key('CONFIG_TCG')
if get_option('tcg_interpreter')
summary_info += {'TCG backend': 'TCI (TCG with bytecode interpreter, experimental and slow)'}
elif get_option('tcg_threaded_interpreter')
summary_info += {'TCG backend': 'TCTI (TCG with threaded-dispatch bytecode interpreter, experimental and slow; but faster than TCI)'}
else
summary_info += {'TCG backend': 'native (@0@)'.format(cpu)}
endif
Expand Down
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ option('tcg', type: 'feature', value: 'auto',
description: 'TCG support')
option('tcg_interpreter', type: 'boolean', value: false,
description: 'TCG with bytecode interpreter (experimental and slow)')
option('tcg_threaded_interpreter', type: 'boolean', value: false,
description: 'TCG with threaded-dispatch bytecode interpreter (experimental and slow, but less slow than TCI)')
option('cfi', type: 'boolean', value: 'false',
description: 'Control-Flow Integrity (CFI)')
option('cfi_debug', type: 'boolean', value: 'false',
Expand Down
24 changes: 12 additions & 12 deletions scripts/mtest2make.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ def process_tests(test, targets, suites):
print('run-test-%d: $(.test.deps.%d)' % (i,i))
print('\t@$(call .test.run,%d,$(.test.output-format))' % (i,))

test_suites = test['suite'] or ['default']
is_slow = any(s.endswith('-slow') for s in test_suites)
for s in test_suites:
# The suite name in the introspection info is "PROJECT:SUITE"
s = s.split(':')[1]
if s.endswith('-slow'):
s = s[:-5]
if is_slow:
suites[s].slow_tests.append(i)
else:
suites[s].tests.append(i)
suites[s].executables.add(executable)
#test_suites = test['suite'] or ['default']
#is_slow = any(s.endswith('-slow') for s in test_suites)
#for s in test_suites:
# # The suite name in the introspection info is "PROJECT:SUITE"
# s = s.split(':')[1]
# if s.endswith('-slow'):
# s = s[:-5]
# if is_slow:
# suites[s].slow_tests.append(i)
# else:
# suites[s].tests.append(i)
# suites[s].executables.add(executable)

def emit_prolog(suites, prefix):
all_tap = ' '.join(('%s-report-%s.tap' % (prefix, k) for k in suites.keys()))
Expand Down
Loading

0 comments on commit 376dc65

Please sign in to comment.