Cleanup includes for no-TCG builds
Subsystems (2)
cover Cleanup includes for no-TCG builds
Right now, accel/tcg and tcg/$tcg_target are part of the include path for all builds, mostly due to exec/translate-all.h and the flush_icache_range function. But there's also a few useless tcg/tcg.h includes that can simply be removed.
This small series, mostly consisting of code movement and file renames, starts cleaning up this area.
Paolo
Paolo Bonzini (3):
remove TCG includes from common code
move icache flush out of tcg.h
trace: do not include TCG helper tracepoints in no-TCG builds
accel/stubs/tcg-stub.c | 1 -
accel/tcg/cputlb.c | 2 +-
accel/tcg/translate-all.c | 2 +-
accel/tcg/user-exec.c | 2 +-
cpu.c | 2 +-
hw/i386/kvmvapic.c | 1 -
include/exec/flush-icache.h | 64 +++++++++++++++++++++
{accel/tcg => include/exec}/translate-all.h | 0
monitor/misc.c | 1 -
softmmu/physmem.c | 4 +-
tcg/aarch64/tcg-target.h | 5 --
tcg/arm/tcg-target.h | 5 --
tcg/i386/tcg-target.h | 4 --
tcg/mips/tcg-target.h | 11 ----
tcg/ppc/tcg-target.c.inc | 22 --------
tcg/ppc/tcg-target.h | 1 -
tcg/riscv/tcg-target.h | 5 --
tcg/s390/tcg-target.h | 4 --
tcg/sparc/tcg-target.h | 8 ---
tcg/tcg.c | 1 +
tcg/tci/tcg-target.h | 4 --
trace/meson.build | 2 +-
util/cacheinfo.c | 25 +++++++++
23 files changed, 97 insertions(+), 79 deletions(-)
create mode 100644 include/exec/flush-icache.h
rename {accel/tcg => include/exec}/translate-all.h (100%)Signature · 1 line
2.28.0
PATCH 1/3 remove TCG includes from common code
Enable removing tcg/$tcg_arch from the include path when TCG is disabled. Move translate-all.h to include/exec, since stubs exist for the functions defined therein.
---
accel/stubs/tcg-stub.c | 1 -
accel/tcg/cputlb.c | 2 +-
accel/tcg/translate-all.c | 2 +-
accel/tcg/user-exec.c | 2 +-
cpu.c | 2 +-
hw/i386/kvmvapic.c | 1 -
{accel/tcg => include/exec}/translate-all.h | 0
monitor/misc.c | 1 -
softmmu/physmem.c | 3 +--
9 files changed, 5 insertions(+), 9 deletions(-)
rename {accel/tcg => include/exec}/translate-all.h (100%)accel/stubs/tcg-stub.c +0 -1
@@ -12,7 +12,6 @@#include "qemu/osdep.h" #include "cpu.h" -#include "tcg/tcg.h" #include "exec/exec-all.h" void tb_flush (CPUState *cpu)
accel/tcg/cputlb.c +1 -1
@@ -33,7 +33,7 @@#include "exec/helper-proto.h" #include "qemu/atomic.h" #include "qemu/atomic128.h" -#include "translate-all.h" +#include "exec/translate-all.h" #include "trace/trace-root.h" #include "trace/mem.h" #ifdef CONFIG_PLUGIN
accel/tcg/translate-all.c +1 -1
@@ -49,7 +49,7 @@#include "exec/cputlb.h" #include "exec/tb-hash.h" -#include "translate-all.h" +#include "exec/translate-all.h" #include "qemu/bitmap.h" #include "qemu/error-report.h" #include "qemu/qemu-print.h"
accel/tcg/user-exec.c +1 -1
@@ -23,7 +23,7 @@#include "tcg/tcg.h" #include "qemu/bitops.h" #include "exec/cpu_ldst.h" -#include "translate-all.h" +#include "exec/translate-all.h" #include "exec/helper-proto.h" #include "qemu/atomic128.h" #include "trace/trace-root.h"
cpu.c +1 -1
@@ -34,7 +34,7 @@#include "sysemu/tcg.h" #include "sysemu/kvm.h" #include "sysemu/replay.h" -#include "translate-all.h" +#include "exec/translate-all.h" #include "exec/log.h" uintptr_t qemu_host_page_size;
hw/i386/kvmvapic.c +0 -1
@@ -21,7 +21,6 @@#include "hw/sysbus.h" #include "hw/boards.h" #include "migration/vmstate.h" -#include "tcg/tcg.h" #include "qom/object.h" #define VAPIC_IO_PORT 0x7e
include/exec/translate-all.h renamed from accel/tcg/translate-all.h +0 -0
monitor/misc.c +0 -1
@@ -77,7 +77,6 @@#include "qapi/qmp-event.h" #include "sysemu/cpus.h" #include "qemu/cutils.h" -#include "tcg/tcg.h" #if defined(TARGET_S390X )#include "hw/s390x/storage-keys.h"
softmmu/physmem.c +1 -2
@@ -25,7 +25,6 @@#include "cpu.h" #include "exec/exec-all.h" #include "exec/target_page.h" -#include "tcg/tcg.h" #include "hw/qdev-core.h" #include "hw/qdev-properties.h" #include "hw/boards.h"
@@ -53,7 +52,7 @@#include "qemu/rcu_queue.h" #include "qemu/main-loop.h" -#include "translate-all.h" +#include "exec/translate-all.h" #include "sysemu/replay.h" #include "exec/memory-internal.h"
Signature · 1 line
2.28.0
Re: [PATCH 1/3] remove TCG includes from common code
Quoted 5 lines · Paolo Bonzini
Enable removing tcg/$tcg_arch from the include path when TCG is disabled. Move
translate-all.htoinclude/exec, since stubs exist for the functions defined therein.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 12 lines
---
accel/stubs/tcg-stub.c | 1 -
accel/tcg/cputlb.c | 2 +-
accel/tcg/translate-all.c | 2 +-
accel/tcg/user-exec.c | 2 +-
cpu.c | 2 +-
hw/i386/kvmvapic.c | 1 -
{accel/tcg => include/exec}/translate-all.h | 0
monitor/misc.c | 1 -
softmmu/physmem.c | 3 +--
9 files changed, 5 insertions(+), 9 deletions(-)
rename {accel/tcg => include/exec}/translate-all.h (100%)r~
Re: [PATCH 1/3] remove TCG includes from common code
In reply to Paolo BonziniQuoted 5 lines · Paolo Bonzini
Enable removing tcg/$tcg_arch from the include path when TCG is disabled. Move
translate-all.htoinclude/exec, since stubs exist for the functions defined therein.Signed-off-by Paolo Bonzini <[email protected]>
Quoted 11 lines
---
accel/stubs/tcg-stub.c | 1 -
accel/tcg/cputlb.c | 2 +-
accel/tcg/translate-all.c | 2 +-
accel/tcg/user-exec.c | 2 +-
cpu.c | 2 +-
hw/i386/kvmvapic.c | 1 -
{accel/tcg => include/exec}/translate-all.h | 0
monitor/misc.c | 1 -
softmmu/physmem.c | 3 +--
9 files changed, 5 insertions(+), 9 deletions(-)PATCH 2/3 move icache flush out of tcg.h
In reply to Paolo Bonziniicache flush is also used by non-TCG accelerators. Do not require users such as physmem.c to include tcg/tcg.h.
--- include/exec/flush-icache.h | 64 ++++++++++++++++++++++++++++++++++++++++ softmmu/physmem.c | 1 + tcg/aarch64/tcg-target.h | 5 ---- tcg/arm/tcg-target.h | 5 ---- tcg/i386/tcg-target.h | 4 --- tcg/mips/tcg-target.h | 11 ------- tcg/ppc/tcg-target.c.inc | 22 -------------- tcg/ppc/tcg-target.h | 1 - tcg/riscv/tcg-target.h | 5 ---- tcg/s390/tcg-target.h | 4 --- tcg/sparc/tcg-target.h | 8 ----- tcg/tcg.c | 1 + tcg/tci/tcg-target.h | 4 --- util/cacheinfo.c | 25 ++++++++++++++++ 14 files changed, 91 insertions(+), 69 deletions(-) create mode 100644 include/exec/flush-icache.h
include/exec/flush-icache.h new file +64 -0
@@ -0,0 +1,64 @@ +/* +* icache flush for QEMU (both TCG or virtualized) +* +* Copyright (c) 2003-2020 QEMU contributors +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef FLUSH_ICACHE_H +#define FLUSH_ICACHE_H + +#if definedHOST_I386 || definedHOST_X86_64 || definedHOST_S390 || definedHOST_S390X +static inline void flush_icache_range (uintptr_t start,uintptr_t stop) +{ +} + +#elif definedHOST_MIPS +#ifdef __OpenBSD__ +#include <machine/sysarch.h> +#else +#include <sys/cachectl.h> +#endif + +static inline void flush_icache_range (uintptr_t start,uintptr_t stop) +{ +cacheflush ((void *)start, stop-start,ICACHE ); +} + +#elif definedHOST_PPC || definedHOST_PPC64 +extern void flush_icache_range (uintptr_t start,uintptr_t stop); + +#elif definedHOST_SPARC +static inline void flush_icache_range (uintptr_t start,uintptr_t stop) +{ +uintptr_t p; +for (p = start &-8 ; p < ((stop +7 ) &-8 ); p +=8 ) { + __asm__ __volatile__("flush\t%0" : :"r" (p)); + } +} + +#elif definedHOST_AARCH64 || definedHOST_ARM || definedHOST_RISCV +static inline void flush_icache_range (uintptr_t start,uintptr_t stop) +{ +__builtin___clear_cache ((char *)start, (char *)stop); +} +#elif definedCONFIG_TCG_INTERPRETER +static inline void flush_icache_range (uintptr_t start,uintptr_t stop) +{ +assert (tcg_enabled ()); +} +#endif + +#endif
softmmu/physmem.c +1 -0
@@ -53,6 +53,7 @@#include "qemu/rcu_queue.h" #include "qemu/main-loop.h" #include "exec/translate-all.h" +#include "exec/flush-icache.h" #include "sysemu/replay.h" #include "exec/memory-internal.h"
tcg/aarch64/tcg-target.h +0 -5
@@ -148,11 +148,6 @@ typedef enum {#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -__builtin___clear_cache ((char *)start, (char *)stop); -} -void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );#ifdef CONFIG_SOFTMMU
tcg/arm/tcg-target.h +0 -5
@@ -134,11 +134,6 @@ enum {#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -__builtin___clear_cache ((char *) start, (char *) stop); -} -/* not defined -- call should be eliminated at compile time */ void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );
tcg/i386/tcg-target.h +0 -4
@@ -206,10 +206,6 @@ extern bool have_avx2;#define TCG_TARGET_extract_i64_valid (ofs, len) \ (((ofs) == 8 && (len) == 8) || ((ofs) + (len)) == 32) -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -} -static inline void tb_target_set_jmp_target (uintptr_t tc_ptr,uintptr_t jmp_addr,uintptr_t addr) {
tcg/mips/tcg-target.h +0 -11
@@ -198,20 +198,9 @@ extern bool use_mips32r2_instructions;#define TCG_TARGET_HAS_ext16u_i64 0/* andi rt, rs, 0xffff */ #endif -#ifdef __OpenBSD__ -#include <machine/sysarch.h> -#else -#include <sys/cachectl.h> -#endif -#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -cacheflush ((void *)start, stop-start,ICACHE ); -} -void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );#ifdef CONFIG_SOFTMMU
tcg/ppc/tcg-target.c.inc +0 -22
@@ -3863,25 +3863,3 @@ void tcg_register_jit(void *buf, size_t buf_size) tcg_register_jit_int(buf, buf_size, &debug_frame, sizeof(debug_frame)); } #endif /* __ELF__ */ - -void flush_icache_range(uintptr_t start, uintptr_t stop) -{ - uintptr_t p, start1, stop1; - size_t dsize = qemu_dcache_linesize; - size_t isize = qemu_icache_linesize; - - start1 = start & ~(dsize - 1); - stop1 = (stop + dsize - 1) & ~(dsize - 1); - for (p = start1; p < stop1; p += dsize) { - asm volatile ("dcbst 0,%0" : : "r"(p) : "memory"); - } - asm volatile ("sync" : : : "memory"); - - start &= start & ~(isize - 1); - stop1 = (stop + isize - 1) & ~(isize - 1); - for (p = start1; p < stop1; p += isize) { - asm volatile ("icbi 0,%0" : : "r"(p) : "memory"); - } - asm volatile ("sync" : : : "memory"); - asm volatile ("isync" : : : "memory"); -}
tcg/ppc/tcg-target.h +0 -1
@@ -175,7 +175,6 @@ extern bool have_vsx;#define TCG_TARGET_HAS_bitsel_vec have_vsx#define TCG_TARGET_HAS_cmpsel_vec 0 -void flush_icache_range (uintptr_t start,uintptr_t stop);void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );#define TCG_TARGET_DEFAULT_MO (0)
tcg/riscv/tcg-target.h +0 -5
@@ -159,11 +159,6 @@ typedef enum {#define TCG_TARGET_HAS_mulsh_i64 1#endif -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -__builtin___clear_cache ((char *)start, (char *)stop); -} -/* not defined -- call should be eliminated at compile time */ void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );
tcg/s390/tcg-target.h +0 -4
@@ -145,10 +145,6 @@ enum { TCG_AREG0 = TCG_REG_R10, }; -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -} -static inline void tb_target_set_jmp_target (uintptr_t tc_ptr,uintptr_t jmp_addr,uintptr_t addr) {
tcg/sparc/tcg-target.h +0 -8
@@ -168,14 +168,6 @@ extern bool use_vis3_instructions;#define TCG_TARGET_DEFAULT_MO (0)#define TCG_TARGET_HAS_MEMORY_BSWAP 1 -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -uintptr_t p; -for (p = start &-8 ; p < ((stop +7 ) &-8 ); p +=8 ) { - __asm__ __volatile__("flush\t%0" : :"r" (p)); - } -} -void tb_target_set_jmp_target (uintptr_t ,uintptr_t ,uintptr_t );#define TCG_TARGET_NEED_POOL_LABELS
tcg/tcg.c +1 -0
@@ -43,6 +43,7 @@#include "cpu.h" #include "exec/exec-all.h" +#include "exec/flush-icache.h" #if !defined(CONFIG_USER_ONLY )#include "hw/boards.h"
tcg/tci/tcg-target.h +0 -4
@@ -191,10 +191,6 @@ void tci_disas(uint8_t opc);#define HAVE_TCG_QEMU_TB_EXEC -static inline void flush_icache_range (uintptr_t start,uintptr_t stop) -{ -} -/* We could notice __i386__ or __s390x__ and reduce the barriers depending on the host. But if you want performance, you use the normal backend. We prefer consistency across hosts on this. */
util/cacheinfo.c +25 -0
@@ -9,6 +9,7 @@#include "qemu/osdep.h" #include "qemu/host-utils.h" #include "qemu/atomic.h" +#include "exec/flush-icache.h" int qemu_icache_linesize =0 ;int qemu_icache_linesize_log;
@@ -177,6 +178,30 @@ static void fallback_cache_info(int *isize, int *dsize) } } +#if definedHOST_PPC || definedHOST_PPC64 +void flush_icache_range (uintptr_t start,uintptr_t stop) +{ +uintptr_t p, start1, stop1; +size_t dsize = qemu_dcache_linesize; +size_t isize = qemu_icache_linesize; + + start1 = start & ~(dsize -1 ); + stop1 = (stop + dsize -1 ) & ~(dsize -1 ); +for (p = start1; p < stop1; p += dsize) { + asmvolatile ("dcbst 0,%0" : :"r" (p) :"memory" ); + } + asmvolatile ("sync" : : :"memory" ); + + start &= start & ~(isize -1 ); + stop1 = (stop + isize -1 ) & ~(isize -1 ); +for (p = start1; p < stop1; p += isize) { + asmvolatile ("icbi 0,%0" : :"r" (p) :"memory" ); + } + asmvolatile ("sync" : : :"memory" ); + asmvolatile ("isync" : : :"memory" ); +} +#endif +static void __attribute__((constructor))init_cache_info (void ) {int isize =0 , dsize =0 ;
Signature · 1 line
2.28.0
Re: [PATCH 2/3] move icache flush out of tcg.h
Quoted 5 lines · Paolo Bonzini
icache flush is also used by non-TCG accelerators. Do not require users such as
physmem.cto includetcg/tcg.h.Signed-off-by Paolo Bonzini <[email protected]>---
See also
https://lists.gnu.org/archive/html/qemu-devel/2020-12/msg03623.html
I moved it to a new file, rather than into cacheinfo.c.
r~
Re: [PATCH 2/3] move icache flush out of tcg.h
Quoted 4 lines · Richard Henderson
Quoted 3 lines · Paolo Bonzini
icache flush is also used by non-TCG accelerators. Do not require users such as
physmem.cto includetcg/tcg.h.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Paolo Bonzini <[email protected]>---
See also
https://lists.gnu.org/archive/html/qemu-devel/2020-12/msg03623.html
I moved it to a new file, rather than into
cacheinfo.c.
Oh, I missed that. I'll pick your patch instead of this one.
Paolo
PATCH 3/3 trace: do not include TCG helper tracepoints in no-TCG builds
In reply to Paolo Bonzini--- trace/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
trace/meson.build +1 -1
@@ -71,7 +71,7 @@ foreach d : [ input: meson.project_source_root() / 'trace-events', command: [ tracetool, '--group=root', '--format=@0@'.format(d[1]), '@INPUT@' ], capture: true) - specific_ss.add(gen) + specific_ss.add(when: 'CONFIG_TCG', if_true: gen) endforeach if 'CONFIG_TRACE_UST' in config_host
Signature · 1 line
2.28.0
Re: [PATCH 3/3] trace: do not include TCG helper tracepoints in no-TCG builds
trace/meson.build foreach d : [ · line 75
Quoted 11 lines · Paolo Bonzini
trace/meson.build +1
-1@@ -71,7 +71,7 @@ foreach d : [ input: meson.project_source_root() / 'trace-events', command: [ tracetool, '--group=root', '--format=@0@'.format(d[1]), '@INPUT@' ], capture: true) - specific_ss.add(gen) + specific_ss.add(when: 'CONFIG_TCG', if_true: gen) endforeach
Sure, unless it makes more sense to conditionalize the entire loop, so that those targets aren't even created?
r~
Re: [PATCH 3/3] trace: do not include TCG helper tracepoints in no-TCG builds
Quoted 10 lines · Richard Henderson
trace/meson.build foreach d : [ · line 75
Quoted 7 lines
trace/meson.build +1
-1@@ -71,7 +71,7 @@ foreach d : [ input: meson.project_source_root() / 'trace-events', command: [ tracetool, '--group=root', '--format=@0@'.format(d[1]), '@INPUT@' ], capture: true) - specific_ss.add(gen) + specific_ss.add(when: 'CONFIG_TCG', if_true: gen) endforeachSure, unless it makes more sense to conditionalize the entire loop, so that those targets aren't even created?
The targets exist but the files won't be created (the rules will be in build.ninja but they'll be orphan).
Paolo
Re: [PATCH 3/3] trace: do not include TCG helper tracepoints in no-TCG builds
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Richard Henderson
Quoted 8 lines
trace/meson.build +1
-1@@ -71,7 +71,7 @@ foreach d : [ input: meson.project_source_root() / 'trace-events', command: [ tracetool, '--group=root', '--format=@0@'.format(d[1]), '@INPUT@' ], capture: true) - specific_ss.add(gen) + specific_ss.add(when: 'CONFIG_TCG', if_true: gen)endforeach
Sure, unless it makes more sense to conditionalize the entire loop, so that those targets aren't even created?
Quoted 2 lines
The targets exist but the files won't be created (the rules will be in build.ninja but they'll be orphan).
Yes, I get that. So... is there a reason for them to be there, when it seems just as easy for them not to be?
r~
Re: [PATCH 3/3] trace: do not include TCG helper tracepoints in no-TCG builds
Quoted 14 lines · Richard Henderson
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Richard Henderson
trace/meson.build foreach d : [ · line 76
Quoted 8 lines
trace/meson.build +1
-1@@ -71,7 +71,7 @@ foreach d : [ input: meson.project_source_root() / 'trace-events', command: [ tracetool, '--group=root', '--format=@0@'.format(d[1]), '@INPUT@' ], capture: true) - specific_ss.add(gen) + specific_ss.add(when: 'CONFIG_TCG', if_true: gen) endforeachSure, unless it makes more sense to conditionalize the entire loop, so that those targets aren't even created?
Quoted 5 lines
Quoted 2 lines
The targets exist but the files won't be created (the rules will be in build.ninja but they'll be orphan).
Yes, I get that. So... is there a reason for them to be there, when it seems just as easy for them not to be?
Just a dislike for "if"s when conditional add() will do.
Speaking in general, I like the various sections of the meson.build files to use either foreach (taking the job of Makefile target pattern rules, where "if"s add complication) or if (taking the job of configure code, where loops are rare). It can't always be done, but it helps limiting the amount of spaghetti...
Paolo