Skip to contentSkip to conversation

add disable-tcg option for x86 build

PATCH In review Yang Zhong 4 participants 27 messages Jul 3, 2017 – Jul 4, 2017 Kbuild

lore
Share & tools
lore

Yang Zhong

author
#0 lore raw

v2 cover add disable-tcg option for x86 build

This patchset rebased from Paolo's below patchset, which was based on QEMU 2.0.50 version.
https://github.com/bonzini/qemu/tree/disable-tcg

Since qemu-system-x86_64 enabled kvm and TCG accelators by default, in fact, the TCG accelator is NOT useful in the system build of x86 platform. This patchset will disable TCG for x86 platform if --disable-tcg option is added into ./configure command.

The new configure build command like below
(1)./configure
tcg is defaultly enabled

(2)./configure --disable-tcg --target-list=x86_64-softmmu
tcg is disabled in x86_64-softmmu

(3)./configure --disable-tcg --target-list=i386-softmmu
tcg is disabled in i386-softmmu

How to verify disable-tcg option
(1)./configure
a)all user and softmmu build are okay.
b) CONFIG_TCG=y is set in $config_target_mak in all user and softmmu directory c)kvm starting vm is okay

     ./qemu-system-x86_64 -enable-kvm -cpu host -m 2G -smp cpus=4,cores=4,threads=1,\
       sockets=1 -drive format=raw,file=eywa.img,index=0,media=disk -nographic -serial \
       stdio -nodefaults

d)tcg starting vm is okay
./qemu-system-x86_64 -m 2G -smp cpus=4,cores=4,threads=1,sockets=1 -drive format=raw,\
file=eywa.img,index=0,media=disk -nographic -serial stdio -nodefaults

(2)./configure --disable-tcg --target-list=x86_64-softmmu
a) softmmu build is okay.
b) CONFIG_TCG=y is not set in $config_target_mak in x86_64-softmmu directory
c) kvm starting vm is okay

     ./qemu-system-x86_64 -enable-kvm -cpu host -m 2G -smp cpus=4,cores=4,threads=1,\
       sockets=1 -drive format=raw,file=eywa.img,index=0,media=disk -nographic -serial \
       stdio -nodefaults

d) tcg starting vm is aborted
The log as below:
"tcg" accelerator not found.
No accelerator found!

(3)./configure --target-list=x86_64-softmmu,x86_64-linux-user
ERROR: The current x86_64-linux-user can't support disable-tcg,
only i386-softmmu|x86_64-softmmu support disable-tcg

(4)./configure --disable-tcg --target-list=arm-softmmu
ERROR: The current arm-softmmu can't support disable-tcg,
only i386-softmmu|x86_64-softmmu support disable-tcg

v2:
* updated patch 01 reviewed by Richard Henderson,Thomas Huth and Paolo. "echo "CONFIG_TCG" >> $config_target_mak" is more clean.
add the error configure check for --disable-tcg.
new patch is easy to extend to other platform.
* updated patch 02 reviewed by Paolo.
remove CONFIG_TCG.
add tcg_enabled() for tcg code.
* updated patch 03 reviewed by Paolo.
move tcg_handle_interrupt() from translate-common.c to tcg-all.c.
* updated patch 09 reviewed by Paolo and Richard Henderson. moved the x86 related function out of stubs file.
added patch 14 for x86 related tcg functions.
* updated the flush_icache_range() reviewed by Paolo.
deleted this patch and the compile is still okay. So there will not this patch in future release.
* updated patch 12 reviewed by Richard Henderson.
removed the CONFIG_TCG in CPUX86State struct. cpu-defs.h has disabled CPU_COMMON_TLB if tcg is disabled.

Yang Zhong (15):
configure: add the disable-tcg option
vl: add tcg_enabled() for tcg related code
tcg: tcg_handle_interrupt() function
tcg: change tcg_enabled()
tcg: move page_size_init() function
kvmvapic: remove tcg related code
tcg: move cpu_sync_bndcs_hflags() function
tcg: make cpu_get_fp80()/cpu_set_fp80() static
tcg: add the tcg-stub.c file into accel/stubs/
tcg: move tb related lock functions
tcg: split cpu_set_mxcsr() and make cpu_set_fpuc() inline
tcg: disable tcg in CPUX86State struct
tcg: add the CONFIG_TCG for header
tcg: add the tcg_enabled() in target/i386/
tcg: add the CONFIG_TCG into Makefiles

 Makefile.target              |  4 +-
 accel/Makefile.objs          |  2 +-
 accel/stubs/Makefile.objs    |  1 +
 accel/stubs/tcg-stub.c       | 94 ++++++++++++++++++++++++++++++++++++++++++++
 accel/tcg/Makefile.objs      |  2 +-
 accel/tcg/cpu-exec.c         |  1 +
 accel/tcg/cputlb.c           |  1 +
 accel/tcg/tcg-all.c          | 36 ++++++++++++++++-
 accel/tcg/translate-all.c    | 24 +----------
 accel/tcg/translate-all.h    |  3 ++
 accel/tcg/translate-common.c | 56 --------------------------
 bsd-user/main.c              |  1 +
 configure                    | 43 +++++++++++++++++++-
 exec.c                       | 20 ++++++++++
 hw/i386/kvmvapic.c           | 24 -----------
 include/exec/cpu-defs.h      |  4 +-
 include/exec/cputlb.h        |  2 +-
 include/exec/exec-all.h      | 53 +++++++++++++------------
 include/exec/helper-proto.h  |  2 +
 include/qemu-common.h        |  7 +++-
 include/sysemu/accel.h       |  2 +-
 linux-user/main.c            |  2 +-
 qom/cpu.c                    |  2 +
 target/i386/Makefile.objs    |  7 ++--
 target/i386/bpt_helper.c     | 26 +++++++++---
 target/i386/cpu.c            |  4 +-
 target/i386/cpu.h            | 22 +++++++++--
 target/i386/fpu_helper.c     | 29 +-------------
 target/i386/helper.c         | 34 +++++++++++++++-
 target/i386/machine.c        | 23 ++++++++++-
 target/i386/mpx_helper.c     | 30 --------------
 tcg/tcg.h                    |  4 --
 trace/control-target.c       |  1 -
 vl.c                         | 15 +++++--
 34 files changed, 358 insertions(+), 223 deletions(-)
 create mode 100644 accel/stubs/tcg-stub.c
 delete mode 100644 accel/tcg/translate-common.c
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v2 1/15 configure: add the disable-tcg option

Add the disable-tcg option into configure and echo CONFIG_TCG=y into $config_target_mak. The default tcg is enabled for all build, only i386 and x86_64 softmmu option can be disabled. This operation do not make big change with the older build command.

The new configure build command like below
(1)./configure
tcg is defaultly enabled

(2)./configure --disable-tcg --target-list=x86_64-softmmu
tcg is disabled in x86_64-softmmu

(3)./configure --disable-tcg --target-list=i386-softmmu
tcg is disabled in i386-softmmu

If the --target-list include other softmmus or user options, the configure command will report error and configure is aborted.
The error as:
ERROR: The current aarch64-softmmu can't support disable-tcg,
only i386-softmmu|x86_64-softmmu support disable-tcg
or
ERROR: The user build can't support disable-tcg,
only i386-softmmu|x86_64-softmmu support disable-tcg

---
 configure | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
configure +42 -1
index c571ad1..61ce514 100755
@@ -224,6 +224,7 @@ cap_ng=""
 attr=""
 libattr=""
 xfs=""
+tcg="yes"
 
 vhost_net="no"
 vhost_scsi="no"
@@ -953,6 +954,10 @@ for opt do
   ;;
   --enable-hax) hax="yes"
   ;;
+  --disable-tcg) tcg="no"
+  ;;
+  --enable-tcg) tcg="yes"
+  ;;
   --disable-tcg-interpreter) tcg_interpreter="no"
   ;;
   --enable-tcg-interpreter) tcg_interpreter="yes"
@@ -1715,6 +1720,24 @@ case " $target_list " in
   ;;
 esac
 
+if test "$tcg" = "no"; then
+   for target in $target_list; do
+      if test "$softmmu" = "yes"; then
+        case $target in
+           i386-softmmu|x86_64-softmmu)
+           ;;
+        *)
+           error_exit "The current $target can't support disable-tcg,"\
+              "only i386-softmmu|x86_64-softmmu support disable-tcg"
+           ;;
+        esac
+     else
+        error_exit "The user build can't support disable-tcg,"\
+           "only i386-softmmu|x86_64-softmmu support disable-tcg"
+     fi
+   done
+fi
+
 feature_not_found() {
   feature=$1
   remedy=$2
@@ -5119,7 +5142,6 @@ echo "module support    $modules"
 echo "host CPU          $cpu"
 echo "host big endian   $bigendian"
 echo "target list       $target_list"
-echo "tcg debug enabled $debug_tcg"
 echo "gprof enabled     $gprof"
 echo "sparse enabled    $sparse"
 echo "strip binaries    $strip_opt"
@@ -5173,6 +5195,11 @@ echo "Linux AIO support $linux_aio"
 echo "ATTR/XATTR support $attr"
 echo "Install blobs     $blobs"
 echo "KVM support       $kvm"
+echo "TCG support       $tcg"
+if test "$tcg" = "yes" ; then
+    echo "TCG debug enabled $debug_tcg"
+    echo "TCG interpreter   $tcg_interpreter"
+fi
 echo "HAX support       $hax"
 echo "RDMA support      $rdma"
 echo "TCG interpreter   $tcg_interpreter"
@@ -6231,6 +6258,7 @@ fi
 if test "$target_user_only" = "yes" ; then
   echo "CONFIG_USER_ONLY=y" >> $config_target_mak
   echo "CONFIG_QEMU_INTERP_PREFIX=\"$interp_prefix1\"" >> $config_target_mak
+  echo "CONFIG_TCG=y" >> $config_target_mak
 fi
 if test "$target_linux_user" = "yes" ; then
   echo "CONFIG_LINUX_USER=y" >> $config_target_mak
@@ -6250,6 +6278,19 @@ if test "$target_bsd_user" = "yes" ; then
   echo "CONFIG_BSD_USER=y" >> $config_target_mak
 fi
 
+if test "$target_softmmu" = "yes" ; then
+   case "$target_name" in
+     i386|x86_64)
+       if test "$tcg" = "yes" ; then
+         echo "CONFIG_TCG=y" >> $config_target_mak
+       fi
+       ;;
+     *)
+       echo "CONFIG_TCG=y" >> $config_target_mak
+       ;;
+   esac
+fi
+
 # generate QEMU_CFLAGS/LDFLAGS for targets
 
 cflags=""
Signature · 1 line
1.9.1
author
#9 lore raw

PATCH v2 2/15 vl: add tcg_enabled() for tcg related code

In reply to Yang Zhong

Need to disable the tcg related code in the vl.c if the disable-tcg option is added into ./configure command.

---
 accel/tcg/tcg-all.c    |  2 +-
 include/sysemu/accel.h |  2 +-
 vl.c                   | 15 +++++++++++----
 3 files changed, 13 insertions(+), 6 deletions(-)
accel/tcg/tcg-all.c +1 -1
index dba9931..b86c896 100644
@@ -28,7 +28,7 @@
 #include "sysemu/sysemu.h"
 #include "qom/object.h"
 
-int tcg_tb_size;
+long tcg_tb_size;
 static bool tcg_allowed = true;
 
 static int tcg_init(MachineState *ms)
include/sysemu/accel.h +1 -1
index ecc5c84..7b905b7 100644
@@ -63,7 +63,7 @@ typedef struct AccelClass {
 #define ACCEL_GET_CLASS(obj) \
     OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL)
 
-extern int tcg_tb_size;
+extern long tcg_tb_size;
 
 void configure_accelerator(MachineState *ms);
 /* Register accelerator specific global properties */
vl.c +11 -4
index 36ff3f4..f28c1ac 100644
@@ -3933,9 +3933,14 @@ int main(int argc, char **argv, char **envp)
                 configure_rtc(opts);
                 break;
             case QEMU_OPTION_tb_size:
-                tcg_tb_size = strtol(optarg, NULL, 0);
-                if (tcg_tb_size < 0) {
-                    tcg_tb_size = 0;
+                if (tcg_enabled()) {
+                    qemu_strtol(optarg, NULL, 0, &tcg_tb_size);
+                    if (tcg_tb_size < 0) {
+                        tcg_tb_size = 0;
+                    }
+                } else {
+                    error_report("TCG is disabled");
+                    exit(1);
                 }
                 break;
             case QEMU_OPTION_icount:
@@ -4481,7 +4486,9 @@ int main(int argc, char **argv, char **envp)
         qemu_opts_del(icount_opts);
     }
 
-    qemu_tcg_configure(accel_opts, &error_fatal);
+    if (tcg_enabled()) {
+        qemu_tcg_configure(accel_opts, &error_fatal);
+    }
 
     if (default_net) {
         QemuOptsList *net = qemu_find_opts("net");
Signature · 1 line
1.9.1
author
#11 lore raw

PATCH v2 3/15 tcg: tcg_handle_interrupt() function

In reply to Yang Zhong

Move tcg_handle_interrupt() from translate-common.c to accel/tcg/tcg-all.c.

---
 accel/tcg/Makefile.objs      |  2 +-
 accel/tcg/tcg-all.c          | 32 +++++++++++++++++++++++++
 accel/tcg/translate-common.c | 56 --------------------------------------------
 qom/cpu.c                    |  2 ++
 4 files changed, 35 insertions(+), 57 deletions(-)
 delete mode 100644 accel/tcg/translate-common.c
accel/tcg/Makefile.objs +1 -1
index f173cd5..70cd474 100644
@@ -1,3 +1,3 @@
 obj-$(CONFIG_SOFTMMU) += tcg-all.o
 obj-$(CONFIG_SOFTMMU) += cputlb.o
-obj-y += cpu-exec.o cpu-exec-common.o translate-all.o translate-common.o
+obj-y += cpu-exec.o cpu-exec-common.o translate-all.o
accel/tcg/tcg-all.c +32 -0
index b86c896..1b13bc9 100644
@@ -27,13 +27,45 @@
 #include "sysemu/accel.h"
 #include "sysemu/sysemu.h"
 #include "qom/object.h"
+#include "qemu-common.h"
+#include "qom/cpu.h"
+#include "sysemu/cpus.h"
+#include "qemu/main-loop.h"
 
 long tcg_tb_size;
 static bool tcg_allowed = true;
 
+#ifndef CONFIG_USER_ONLY
+/* mask must never be zero, except for A20 change call */
+static void tcg_handle_interrupt(CPUState *cpu, int mask)
+{
+    int old_mask;
+    g_assert(qemu_mutex_iothread_locked());
+
+    old_mask = cpu->interrupt_request;
+    cpu->interrupt_request |= mask;
+
+    /*
+     * If called from iothread context, wake the target cpu in
+     * case its halted.
+     */
+    if (!qemu_cpu_is_self(cpu)) {
+        qemu_cpu_kick(cpu);
+    } else {
+        cpu->icount_decr.u16.high = -1;
+        if (use_icount &&
+            !cpu->can_do_io
+            && (mask & ~old_mask) != 0) {
+            cpu_abort(cpu, "Raised interrupt while not in I/O function");
+        }
+    }
+}
+#endif
+
 static int tcg_init(MachineState *ms)
 {
     tcg_exec_init(tcg_tb_size * 1024 * 1024);
+    cpu_interrupt_handler = tcg_handle_interrupt;
     return 0;
 }
 
accel/tcg/translate-common.c deleted +0 -56

56 lines not on this page · raw message

qom/cpu.c +2 -0
index 5069876..583d864 100644
@@ -31,6 +31,8 @@
 #include "hw/qdev-properties.h"
 #include "trace-root.h"
 
+CPUInterruptHandler cpu_interrupt_handler;
+
 bool cpu_exists(int64_t id)
 {
     CPUState *cpu;
Signature · 1 line
1.9.1
author
#13 lore raw

PATCH v2 4/15 tcg: change tcg_enabled()

In reply to Yang Zhong

Change the tcg_enabled() and make sure user build still enable tcg even x86 softmmu disable tcg.

---
 accel/tcg/tcg-all.c       | 2 +-
 accel/tcg/translate-all.c | 6 +-----
 bsd-user/main.c           | 1 +
 include/qemu-common.h     | 7 ++++++-
 linux-user/main.c         | 2 +-
 5 files changed, 10 insertions(+), 8 deletions(-)
accel/tcg/tcg-all.c +1 -1
index 1b13bc9..979b68a 100644
@@ -33,7 +33,7 @@
 #include "qemu/main-loop.h"
 
 long tcg_tb_size;
-static bool tcg_allowed = true;
+bool tcg_allowed;
 
 #ifndef CONFIG_USER_ONLY
 /* mask must never be zero, except for A20 change call */
accel/tcg/translate-all.c +1 -5
index f6ad46b..bc75294 100644
@@ -802,6 +802,7 @@ static void tb_htable_init(void)
    size. */
 void tcg_exec_init(unsigned long tb_size)
 {
+    tcg_allowed = true;
     cpu_gen_init();
     page_init();
     tb_htable_init();
@@ -813,11 +814,6 @@ void tcg_exec_init(unsigned long tb_size)
 #endif
 }
 
-bool tcg_enabled(void)
-{
-    return tcg_ctx.code_gen_buffer != NULL;
-}
-
 /*
  * Allocate a new translation block. Flush the translation buffer if
  * too many translation blocks or too much generated code.
bsd-user/main.c +1 -0
index 04f95dd..276aea7 100644
@@ -35,6 +35,7 @@
 #include "trace/control.h"
 #include "glib-compat.h"
 
+bool tcg_allowed = true;
 int singlestep;
 unsigned long mmap_min_addr;
 unsigned long guest_base;
include/qemu-common.h +6 -1
index 387ef52..b5adbfa 100644
@@ -76,8 +76,13 @@ int qemu_openpty_raw(int *aslave, char *pty_name);
     sendto(sockfd, buf, len, flags, destaddr, addrlen)
 #endif
 
+extern bool tcg_allowed;
 void tcg_exec_init(unsigned long tb_size);
-bool tcg_enabled(void);
+#ifdef CONFIG_TCG
+#define tcg_enabled() (tcg_allowed)
+#else
+#define tcg_enabled() 0
+#endif
 
 void cpu_exec_init_all(void);
 void cpu_exec_step_atomic(CPUState *cpu);
linux-user/main.c +1 -1
index ad03c9e..a11508a 100644
@@ -38,7 +38,7 @@
 #include "glib-compat.h"
 
 char *exec_path;
-
+bool tcg_allowed = true;
 int singlestep;
 static const char *filename;
 static const char *argv0;
Signature · 1 line
1.9.1
author
#14 lore raw

PATCH v2 5/15 tcg: move page_size_init() function

In reply to Yang Zhong

translate-all.c will be disabled if tcg is disabled in the build, so page_size_init() function and related variables will be moved to exec.c file.

---
 accel/tcg/translate-all.c | 18 ------------------
 exec.c                    | 20 ++++++++++++++++++++
 2 files changed, 20 insertions(+), 18 deletions(-)
accel/tcg/translate-all.c +0 -18
index bc75294..188f5df 100644
@@ -112,9 +112,6 @@ typedef struct PageDesc {
 #define V_L2_BITS 10
 #define V_L2_SIZE (1 << V_L2_BITS)
 
-uintptr_t qemu_host_page_size;
-intptr_t qemu_host_page_mask;
-
 /*
  * L1 Mapping properties
  */
@@ -363,21 +360,6 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr)
     return r;
 }
 
-void page_size_init(void)
-{
-    /* NOTE: we can always suppose that qemu_host_page_size >=
-       TARGET_PAGE_SIZE */
-    qemu_real_host_page_size = getpagesize();
-    qemu_real_host_page_mask = -(intptr_t)qemu_real_host_page_size;
-    if (qemu_host_page_size == 0) {
-        qemu_host_page_size = qemu_real_host_page_size;
-    }
-    if (qemu_host_page_size < TARGET_PAGE_SIZE) {
-        qemu_host_page_size = TARGET_PAGE_SIZE;
-    }
-    qemu_host_page_mask = -(intptr_t)qemu_host_page_size;
-}
-
 static void page_init(void)
 {
     page_size_init();
exec.c +20 -0
index 42ad1ea..ee61915 100644
@@ -118,6 +118,11 @@ __thread CPUState *current_cpu;
    2 = Adaptive rate instruction counting.  */
 int use_icount;
 
+uintptr_t qemu_host_page_size;
+intptr_t qemu_host_page_mask;
+uintptr_t qemu_real_host_page_size;
+intptr_t qemu_real_host_page_mask;
+
 bool set_preferred_target_page_bits(int bits)
 {
     /* The target page size is the lowest common denominator for all
@@ -3590,3 +3595,18 @@ err:
 }
 
 #endif
+
+void page_size_init(void)
+{
+    /* NOTE: we can always suppose that qemu_host_page_size >=
+       TARGET_PAGE_SIZE */
+    qemu_real_host_page_size = getpagesize();
+    qemu_real_host_page_mask = -(intptr_t)qemu_real_host_page_size;
+    if (qemu_host_page_size == 0) {
+        qemu_host_page_size = qemu_real_host_page_size;
+    }
+    if (qemu_host_page_size < TARGET_PAGE_SIZE) {
+        qemu_host_page_size = TARGET_PAGE_SIZE;
+    }
+    qemu_host_page_mask = -(intptr_t)qemu_host_page_size;
+}
Signature · 1 line
1.9.1
author
#15 lore raw

PATCH v2 6/15 kvmvapic: remove tcg related code

In reply to Yang Zhong

Since Paolo's below patch has fixed A20 issue
commit bbfa326fc8028e275eddf8c9965c2a1b59405b2e target/i386: enable A20 automatically in system management mod

The tcg code in kvmvapic.c is NOT useful, those code need remove.

---
 hw/i386/kvmvapic.c | 24 ------------------------
 1 file changed, 24 deletions(-)
hw/i386/kvmvapic.c +0 -24
index 82a4955..5b7be5a 100644
@@ -18,7 +18,6 @@
 #include "sysemu/kvm.h"
 #include "hw/i386/apic_internal.h"
 #include "hw/sysbus.h"
-#include "tcg/tcg.h"
 
 #define VAPIC_IO_PORT           0x7e
 
@@ -396,13 +395,9 @@ static void patch_call(VAPICROMState *s, X86CPU *cpu, target_ulong ip,
 static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
 {
     CPUState *cs = CPU(cpu);
-    CPUX86State *env = &cpu->env;
     VAPICHandlers *handlers;
     uint8_t opcode[2];
     uint32_t imm32 = 0;
-    target_ulong current_pc = 0;
-    target_ulong current_cs_base = 0;
-    uint32_t current_flags = 0;
 
     if (smp_cpus == 1) {
         handlers = &s->rom_state.up;
@@ -410,17 +405,6 @@ static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
         handlers = &s->rom_state.mp;
     }
 
-    if (!kvm_enabled()) {
-        cpu_get_tb_cpu_state(env, &current_pc, &current_cs_base,
-                             &current_flags);
-        /* Account this instruction, because we will exit the tb.
-           This is the first instruction in the block. Therefore
-           there is no need in restoring CPU state. */
-        if (use_icount) {
-            --cs->icount_decr.u16.low;
-        }
-    }
-
     pause_all_vcpus();
 
     cpu_memory_rw_debug(cs, ip, opcode, sizeof(opcode), 0);
@@ -455,14 +439,6 @@ static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)
     }
 
     resume_all_vcpus();
-
-    if (!kvm_enabled()) {
-        /* Both tb_lock and iothread_mutex will be reset when
-         *  longjmps back into the cpu_exec loop. */
-        tb_lock();
-        tb_gen_code(cs, current_pc, current_cs_base, current_flags, 1);
-        cpu_loop_exit_noexc(cs);
-    }
 }
 
 void vapic_report_tpr_access(DeviceState *dev, CPUState *cs, target_ulong ip,
Signature · 1 line
1.9.1
author
#18 lore raw

PATCH v2 7/15 tcg: move cpu_sync_bndcs_hflags() function

In reply to Yang Zhong

Move cpu_sync_bndcs_hflags() function from mpx_helper.c to helper.c because mpx_helper.c need be disabled when tcg is disabled.

---
 target/i386/helper.c     | 34 +++++++++++++++++++++++++++++++++-
 target/i386/mpx_helper.c | 30 ------------------------------
 2 files changed, 33 insertions(+), 31 deletions(-)
target/i386/helper.c +33 -1
index ef05059..87fd705 100644
@@ -29,6 +29,36 @@
 #include "hw/i386/apic_internal.h"
 #endif
 
+void cpu_sync_bndcs_hflags(CPUX86State *env)
+{
+    uint32_t hflags = env->hflags;
+    uint32_t hflags2 = env->hflags2;
+    uint32_t bndcsr;
+
+    if ((hflags & HF_CPL_MASK) == 3) {
+        bndcsr = env->bndcs_regs.cfgu;
+    } else {
+        bndcsr = env->msr_bndcfgs;
+    }
+
+    if ((env->cr[4] & CR4_OSXSAVE_MASK)
+        && (env->xcr0 & XSTATE_BNDCSR_MASK)
+        && (bndcsr & BNDCFG_ENABLE)) {
+        hflags |= HF_MPX_EN_MASK;
+    } else {
+        hflags &= ~HF_MPX_EN_MASK;
+    }
+
+    if (bndcsr & BNDCFG_BNDPRESERVE) {
+        hflags2 |= HF2_MPX_PR_MASK;
+    } else {
+        hflags2 &= ~HF2_MPX_PR_MASK;
+    }
+
+    env->hflags = hflags;
+    env->hflags2 = hflags2;
+}
+
 static void cpu_x86_version(CPUX86State *env, int *family, int *model)
 {
     int cpuver = env->cpuid_version;
@@ -1302,10 +1332,12 @@ void cpu_report_tpr_access(CPUX86State *env, TPRAccess access)
         env->tpr_access_type = access;
 
         cpu_interrupt(cs, CPU_INTERRUPT_TPR);
-    } else {
+    } else if (tcg_enabled()) {
         cpu_restore_state(cs, cs->mem_io_pc);
 
         apic_handle_tpr_access_report(cpu->apic_state, env->eip, access);
+    } else {
+        abort();
     }
 }
 #endif /* !CONFIG_USER_ONLY */
target/i386/mpx_helper.c +0 -30
index 7e44820..ade5d24 100644
@@ -24,36 +24,6 @@
 #include "exec/exec-all.h"
 
 
-void cpu_sync_bndcs_hflags(CPUX86State *env)
-{
-    uint32_t hflags = env->hflags;
-    uint32_t hflags2 = env->hflags2;
-    uint32_t bndcsr;
-
-    if ((hflags & HF_CPL_MASK) == 3) {
-        bndcsr = env->bndcs_regs.cfgu;
-    } else {
-        bndcsr = env->msr_bndcfgs;
-    }
-
-    if ((env->cr[4] & CR4_OSXSAVE_MASK)
-        && (env->xcr0 & XSTATE_BNDCSR_MASK)
-        && (bndcsr & BNDCFG_ENABLE)) {
-        hflags |= HF_MPX_EN_MASK;
-    } else {
-        hflags &= ~HF_MPX_EN_MASK;
-    }
-
-    if (bndcsr & BNDCFG_BNDPRESERVE) {
-        hflags2 |= HF2_MPX_PR_MASK;
-    } else {
-        hflags2 &= ~HF2_MPX_PR_MASK;
-    }
-
-    env->hflags = hflags;
-    env->hflags2 = hflags2;
-}
-
 void helper_bndck(CPUX86State *env, uint32_t fail)
 {
     if (unlikely(fail)) {
Signature · 1 line
1.9.1
author
#19 lore raw

PATCH v2 8/15 tcg: make cpu_get_fp80()/cpu_set_fp80() static

In reply to Yang Zhong

Move cpu_get_fp80()/cpu_set_fp80() from fpu_helper.c to machine.c because fpu_helper.c will be disabled if tcg is disabled in the build.

---
 target/i386/cpu.h        |  2 --
 target/i386/fpu_helper.c | 18 ------------------
 target/i386/machine.c    | 18 ++++++++++++++++++
 3 files changed, 18 insertions(+), 20 deletions(-)
target/i386/cpu.h +0 -2
index de0551f..8b3b535 100644
@@ -1418,8 +1418,6 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,
 
 /* op_helper.c */
 /* used for debug or cpu save/restore */
-void cpu_get_fp80(uint64_t *pmant, uint16_t *pexp, floatx80 f);
-floatx80 cpu_set_fp80(uint64_t mant, uint16_t upper);
 
 /* cpu-exec.c */
 /* the following helpers are only usable in user mode simulation as
target/i386/fpu_helper.c +0 -18
index 69ea33a..34fb5fc 100644
@@ -1539,24 +1539,6 @@ void helper_xsetbv(CPUX86State *env, uint32_t ecx, uint64_t mask)
     raise_exception_ra(env, EXCP0D_GPF, GETPC());
 }
 
-void cpu_get_fp80(uint64_t *pmant, uint16_t *pexp, floatx80 f)
-{
-    CPU_LDoubleU temp;
-
-    temp.d = f;
-    *pmant = temp.l.lower;
-    *pexp = temp.l.upper;
-}
-
-floatx80 cpu_set_fp80(uint64_t mant, uint16_t upper)
-{
-    CPU_LDoubleU temp;
-
-    temp.l.upper = upper;
-    temp.l.lower = mant;
-    return temp.d;
-}
-
 /* MMX/SSE */
 /* XXX: optimize by storing fptt and fptags in the static cpu state */
 
target/i386/machine.c +18 -0
index 8c7a822..53587ae 100644
@@ -142,6 +142,24 @@ typedef struct x86_FPReg_tmp {
     uint16_t tmp_exp;
 } x86_FPReg_tmp;
 
+static void cpu_get_fp80(uint64_t *pmant, uint16_t *pexp, floatx80 f)
+{
+    CPU_LDoubleU temp;
+
+    temp.d = f;
+    *pmant = temp.l.lower;
+    *pexp = temp.l.upper;
+}
+
+static floatx80 cpu_set_fp80(uint64_t mant, uint16_t upper)
+{
+    CPU_LDoubleU temp;
+
+    temp.l.upper = upper;
+    temp.l.lower = mant;
+    return temp.d;
+}
+
 static void fpreg_pre_save(void *opaque)
 {
     x86_FPReg_tmp *tmp = opaque;
Signature · 1 line
1.9.1
author
#20 lore raw

PATCH v2 9/15 tcg: add the tcg-stub.c file into accel/stubs/

In reply to Yang Zhong

If tcg is disabled, the functions in tcg-stub.c file will be called. This file is target-independent file, do not include any platform related stub functions into this file.

---
 accel/stubs/Makefile.objs |  1 +
 accel/stubs/tcg-stub.c    | 80 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+)
 create mode 100644 accel/stubs/tcg-stub.c
accel/stubs/Makefile.objs +1 -0
index bd5794f..fdfbf73 100644
@@ -1 +1,2 @@
 obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
+obj-$(call lnot,$(CONFIG_TCG)) += tcg-stub.o
accel/stubs/tcg-stub.c new file +80 -0

80 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#21 lore raw

PATCH v2 10/15 tcg: move tb related lock functions

In reply to Yang Zhong

Move tb_lock()/tb_unlock()/tb_lock_reset() from tcg.h to translate-all.h. tb_lock()/tb_unlock() need be impelemnted in accel/stubs/tcg-stub.c.

---
 accel/stubs/tcg-stub.c    | 8 ++++++++
 accel/tcg/cpu-exec.c      | 1 +
 accel/tcg/cputlb.c        | 1 +
 accel/tcg/translate-all.h | 3 +++
 tcg/tcg.h                 | 4 ----
 trace/control-target.c    | 1 -
 6 files changed, 13 insertions(+), 5 deletions(-)
accel/stubs/tcg-stub.c +8 -0
index a9fe40a..a84a6e6 100644
@@ -20,6 +20,14 @@
 #include "exec/cpu-all.h"
 
 
+void tb_lock(void)
+{
+}
+
+void tb_unlock(void)
+{
+}
+
 void tb_flush(CPUState *cpu)
 {
 }
accel/tcg/cpu-exec.c +1 -0
index 3581618..03b4ea2 100644
@@ -21,6 +21,7 @@
 #include "trace.h"
 #include "disas/disas.h"
 #include "exec/exec-all.h"
+#include "translate-all.h"
 #include "tcg.h"
 #include "qemu/atomic.h"
 #include "sysemu/qtest.h"
accel/tcg/cputlb.c +1 -0
index 1900936..c0efd74 100644
@@ -21,6 +21,7 @@
 #include "qemu/main-loop.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "translate-all.h"
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
 #include "exec/cpu_ldst.h"
accel/tcg/translate-all.h +3 -0
index ba8e4d6..4774f78 100644
@@ -23,6 +23,9 @@
 
 
 /* translate-all.c */
+void tb_lock(void);
+void tb_unlock(void);
+void tb_lock_reset(void);
 void tb_invalidate_phys_page_fast(tb_page_addr_t start, int len);
 void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
                                    int is_cpu_write_access);
tcg/tcg.h +0 -4
index 9e37722..da78721 100644
@@ -757,10 +757,6 @@ void *tcg_malloc_internal(TCGContext *s, int size);
 void tcg_pool_reset(TCGContext *s);
 TranslationBlock *tcg_tb_alloc(TCGContext *s);
 
-void tb_lock(void);
-void tb_unlock(void);
-void tb_lock_reset(void);
-
 /* Called with tb_lock held.  */
 static inline void *tcg_malloc(int size)
 {
trace/control-target.c +0 -1
index 6266e63..2a5efc7 100644
@@ -11,7 +11,6 @@
 #include "cpu.h"
 #include "trace-root.h"
 #include "trace/control.h"
-#include "translate-all.h"
 
 
 void trace_event_set_state_dynamic_init(TraceEvent *ev, bool state)
Signature · 1 line
1.9.1
author
#22 lore raw

PATCH v2 11/15 tcg: split cpu_set_mxcsr() and make cpu_set_fpuc() inline

In reply to Yang Zhong

Split the cpu_set_mxcsr() and make cpu_set_fpuc() inline with specific tcg code.

---
 target/i386/cpu.h        | 18 ++++++++++++++++--
 target/i386/fpu_helper.c | 11 ++---------
 2 files changed, 18 insertions(+), 11 deletions(-)
target/i386/cpu.h +16 -2
index 8b3b535..67a6091 100644
@@ -1643,8 +1643,22 @@ static inline int32_t x86_get_a20_mask(CPUX86State *env)
 }
 
 /* fpu_helper.c */
-void cpu_set_mxcsr(CPUX86State *env, uint32_t val);
-void cpu_set_fpuc(CPUX86State *env, uint16_t val);
+void tcg_update_mxcsr(CPUX86State *env);
+static inline void cpu_set_mxcsr(CPUX86State *env, uint32_t mxcsr)
+{
+    env->mxcsr = mxcsr;
+    if (tcg_enabled()) {
+        tcg_update_mxcsr(env);
+    }
+}
+
+static inline void cpu_set_fpuc(CPUX86State *env, uint16_t fpuc)
+{
+     env->fpuc = fpuc;
+     if (tcg_enabled()) {
+        update_fp_status(env);
+     }
+}
 
 /* mem_helper.c */
 void helper_lock_init(void);
target/i386/fpu_helper.c +2 -9
index 34fb5fc..f0facb9 100644
@@ -1550,12 +1550,11 @@ void helper_xsetbv(CPUX86State *env, uint32_t ecx, uint64_t mask)
 #define SSE_RC_CHOP         0x6000
 #define SSE_FZ              0x8000
 
-void cpu_set_mxcsr(CPUX86State *env, uint32_t mxcsr)
+void tcg_update_mxcsr(CPUX86State *env)
 {
+    uint32_t mxcsr = env->mxcsr;
     int rnd_type;
 
-    env->mxcsr = mxcsr;
-
     /* set rounding mode */
     switch (mxcsr & SSE_RC_MASK) {
     default:
@@ -1581,12 +1580,6 @@ void cpu_set_mxcsr(CPUX86State *env, uint32_t mxcsr)
     set_flush_to_zero((mxcsr & SSE_FZ) ? 1 : 0, &env->fp_status);
 }
 
-void cpu_set_fpuc(CPUX86State *env, uint16_t val)
-{
-    env->fpuc = val;
-    update_fp_status(env);
-}
-
 void helper_ldmxcsr(CPUX86State *env, uint32_t val)
 {
     cpu_set_mxcsr(env, val);
Signature · 1 line
1.9.1
author
#23 lore raw

PATCH v2 12/15 tcg: disable tcg in CPUX86State struct

In reply to Yang Zhong

Add the CONFIG_TCG for CPU_COMMON_TLB in the CPUX86State struct.

---
 include/exec/cpu-defs.h | 4 +++-
 target/i386/cpu.h       | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)
include/exec/cpu-defs.h +3 -1
index 5f4e303..bc8e7f8 100644
@@ -25,7 +25,9 @@
 
 #include "qemu/host-utils.h"
 #include "qemu/queue.h"
+#ifdef CONFIG_TCG
 #include "tcg-target.h"
+#endif
 #ifndef CONFIG_USER_ONLY
 #include "exec/hwaddr.h"
 #endif
@@ -54,7 +56,7 @@ typedef uint64_t target_ulong;
 #error TARGET_LONG_SIZE undefined
 #endif
 
-#if !defined(CONFIG_USER_ONLY)
+#if !defined(CONFIG_USER_ONLY) && defined(CONFIG_TCG)
 /* use a fully associative victim tlb of 8 entries */
 #define CPU_VTLB_SIZE 8
 
target/i386/cpu.h +2 -0
index 67a6091..d4b10a3 100644
@@ -52,7 +52,9 @@
 
 #include "exec/cpu-defs.h"
 
+#ifdef CONFIG_TCG
 #include "fpu/softfloat.h"
+#endif
 
 #define R_EAX 0
 #define R_ECX 1
Signature · 1 line
1.9.1
author
#24 lore raw

PATCH v2 13/15 tcg: add the CONFIG_TCG for header

In reply to Yang Zhong

Add the CONFIG_TCG for exec-all.h. Since function tlb_set_page_with_attrs() is defined in ./accel/tcg/cputlb.c, which will be disabled if tcg is disabled. This function need be implemented in accel/stubs/tcg-stub.c for disable-tcg.

---
 accel/stubs/tcg-stub.c      |  6 +++++
 include/exec/cputlb.h       |  2 +-
 include/exec/exec-all.h     | 53 ++++++++++++++++++++++++---------------------
 include/exec/helper-proto.h |  2 ++
 4 files changed, 37 insertions(+), 26 deletions(-)
accel/stubs/tcg-stub.c +6 -0
index a84a6e6..4e9f7fa 100644
@@ -64,6 +64,12 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t searched_pc)
     return false;
 }
 
+void tlb_set_page_with_attrs(CPUState *cpu, target_ulong vaddr,
+                             hwaddr paddr, MemTxAttrs attrs,
+                             int prot, int mmu_idx, target_ulong size)
+{
+}
+
 void dump_exec_info(FILE *f, fprintf_function cpu_fprintf)
 {
 }
include/exec/cputlb.h +1 -1
index 3f94178..cf296d9 100644
@@ -19,7 +19,7 @@
 #ifndef CPUTLB_H
 #define CPUTLB_H
 
-#if !defined(CONFIG_USER_ONLY)
+#if !defined(CONFIG_USER_ONLY) && defined(CONFIG_TCG)
 /* cputlb.c */
 void tlb_protect_code(ram_addr_t ram_addr);
 void tlb_unprotect_code(ram_addr_t ram_addr);
include/exec/exec-all.h +28 -25

65 lines not on this page · raw message

include/exec/helper-proto.h +2 -0
index 954bef8..417c7b0 100644
@@ -28,7 +28,9 @@ dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \
 
 #include "helper.h"
 #include "trace/generated-helpers.h"
+#ifdef CONFIG_TCG
 #include "tcg-runtime.h"
+#endif
 
 #undef DEF_HELPER_FLAGS_0
 #undef DEF_HELPER_FLAGS_1
Signature · 1 line
1.9.1
author
#25 lore raw

PATCH v2 14/15 tcg: add the tcg_enabled() in target/i386/

In reply to Yang Zhong

Add the tcg_enabled() to disable tcg code in x86 target.

---
 target/i386/bpt_helper.c | 26 ++++++++++++++++++++------
 target/i386/cpu.c        |  4 +++-
 target/i386/machine.c    |  5 +++--
 3 files changed, 26 insertions(+), 9 deletions(-)
target/i386/bpt_helper.c +20 -6
index b3efdc7..083c712 100644
@@ -216,7 +216,9 @@ void breakpoint_handler(CPUState *cs)
         if (cs->watchpoint_hit->flags & BP_CPU) {
             cs->watchpoint_hit = NULL;
             if (check_hw_breakpoints(env, false)) {
-                raise_exception(env, EXCP01_DB);
+                if (tcg_enabled()) {
+                    raise_exception(env, EXCP01_DB);
+                }
             } else {
                 cpu_loop_exit_noexc(cs);
             }
@@ -226,7 +228,9 @@ void breakpoint_handler(CPUState *cs)
             if (bp->pc == env->eip) {
                 if (bp->flags & BP_CPU) {
                     check_hw_breakpoints(env, true);
-                    raise_exception(env, EXCP01_DB);
+                    if (tcg_enabled()) {
+                        raise_exception(env, EXCP01_DB);
+                    }
                 }
                 break;
             }
@@ -241,7 +245,9 @@ void helper_single_step(CPUX86State *env)
     check_hw_breakpoints(env, true);
     env->dr[6] |= DR6_BS;
 #endif
-    raise_exception(env, EXCP01_DB);
+    if (tcg_enabled()) {
+        raise_exception(env, EXCP01_DB);
+    }
 }
 
 void helper_rechecking_single_step(CPUX86State *env)
@@ -282,7 +288,9 @@ void helper_set_dr(CPUX86State *env, int reg, target_ulong t0)
         cpu_x86_update_dr7(env, t0);
         return;
     }
-    raise_exception_err_ra(env, EXCP06_ILLOP, 0, GETPC());
+    if (tcg_enabled()) {
+        raise_exception_err_ra(env, EXCP06_ILLOP, 0, GETPC());
+    }
 #endif
 }
 
@@ -304,7 +312,11 @@ target_ulong helper_get_dr(CPUX86State *env, int reg)
             return env->dr[7];
         }
     }
-    raise_exception_err_ra(env, EXCP06_ILLOP, 0, GETPC());
+    if (tcg_enabled()) {
+        raise_exception_err_ra(env, EXCP06_ILLOP, 0, GETPC());
+    } else {
+        return 0;
+    }
 }
 
 /* Check if Port I/O is trapped by a breakpoint.  */
@@ -329,7 +341,9 @@ void helper_bpt_io(CPUX86State *env, uint32_t port,
     if (hit) {
         env->dr[6] = (env->dr[6] & ~0xf) | hit;
         env->eip = next_eip;
-        raise_exception(env, EXCP01_DB);
+        if (tcg_enabled()) {
+            raise_exception(env, EXCP01_DB);
+        }
     }
 #endif
 }
target/i386/cpu.c +3 -1
index 642519a..c571772 100644
@@ -4040,8 +4040,10 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->class_by_name = x86_cpu_class_by_name;
     cc->parse_features = x86_cpu_parse_featurestr;
     cc->has_work = x86_cpu_has_work;
+#ifdef CONFIG_TCG
     cc->do_interrupt = x86_cpu_do_interrupt;
     cc->cpu_exec_interrupt = x86_cpu_exec_interrupt;
+#endif
     cc->dump_state = x86_cpu_dump_state;
     cc->get_crash_info = x86_cpu_get_crash_info;
     cc->set_pc = x86_cpu_set_pc;
@@ -4070,7 +4072,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
     cc->gdb_core_xml_file = "i386-32bit.xml";
     cc->gdb_num_core_regs = 41;
 #endif
-#ifndef CONFIG_USER_ONLY
+#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY)
     cc->debug_excp_handler = breakpoint_handler;
 #endif
     cc->cpu_exec_enter = x86_cpu_exec_enter;
target/i386/machine.c +3 -2
index 53587ae..b78b36c 100644
@@ -280,8 +280,9 @@ static int cpu_post_load(void *opaque, int version_id)
     for(i = 0; i < 8; i++) {
         env->fptags[i] = (env->fptag_vmstate >> i) & 1;
     }
-    update_fp_status(env);
-
+    if (tcg_enabled()) {
+        update_fp_status(env);
+    }
     cpu_breakpoint_remove_all(cs, BP_CPU);
     cpu_watchpoint_remove_all(cs, BP_CPU);
     {
Signature · 1 line
1.9.1
author
#26 lore raw

PATCH v2 15/15 tcg: add the CONFIG_TCG into Makefiles

In reply to Yang Zhong

Add the CONFIG_TCG for frontend and backend's files in the related Makefiles.

---
 Makefile.target           | 4 ++--
 accel/Makefile.objs       | 2 +-
 target/i386/Makefile.objs | 7 ++++---
 3 files changed, 7 insertions(+), 6 deletions(-)
Makefile.target +2 -2
index 0066579..8e185d4 100644
@@ -90,8 +90,8 @@ all: $(PROGS) stap
 # cpu emulator library
 obj-y += exec.o
 obj-y += accel/
-obj-y += tcg/tcg.o tcg/tcg-op.o tcg/optimize.o
-obj-y += tcg/tcg-common.o tcg/tcg-runtime.o
+obj-$(CONFIG_TCG) += tcg/tcg.o tcg/tcg-op.o tcg/optimize.o
+obj-$(CONFIG_TCG) += tcg/tcg-common.o tcg/tcg-runtime.o
 obj-$(CONFIG_TCG_INTERPRETER) += tcg/tci.o
 obj-$(CONFIG_TCG_INTERPRETER) += disas/tci.o
 obj-y += fpu/softfloat.o
accel/Makefile.objs +1 -1
index cd5702f..10666ed 100644
@@ -1,4 +1,4 @@
 obj-$(CONFIG_SOFTMMU) += accel.o
 obj-y += kvm/
-obj-y += tcg/
+obj-$(CONFIG_TCG) += tcg/
 obj-y += stubs/
target/i386/Makefile.objs +4 -3
index 4fcb7f3..fee6c7e 100644
@@ -1,6 +1,7 @@
-obj-y += translate.o helper.o cpu.o bpt_helper.o
-obj-y += excp_helper.o fpu_helper.o cc_helper.o int_helper.o svm_helper.o
-obj-y += smm_helper.o misc_helper.o mem_helper.o seg_helper.o mpx_helper.o
+obj-y += helper.o cpu.o cc_helper.o bpt_helper.o
+obj-$(CONFIG_TCG) += translate.o
+obj-$(CONFIG_TCG) += excp_helper.o fpu_helper.o int_helper.o svm_helper.o
+obj-$(CONFIG_TCG) += smm_helper.o misc_helper.o mem_helper.o seg_helper.o mpx_helper.o
 obj-y += gdbstub.o
 obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o monitor.o
 obj-$(CONFIG_KVM) += kvm.o hyperv.o
Signature · 1 line
1.9.1
#2 lore raw

Re: [Qemu-devel] [PATCH v2 01/15] configure: add the disable-tcg option

In reply to Yang Zhong
Quoted 56 lines · Yang Zhong

Add the disable-tcg option into configure and echo CONFIG_TCG=y into $config_target_mak. The default tcg is enabled for all build, only i386 and x86_64 softmmu option can be disabled. This operation do not make big change with the older build command.

The new configure build command like below
(1)./configure
tcg is defaultly enabled

(2)./configure --disable-tcg --target-list=x86_64-softmmu
tcg is disabled in x86_64-softmmu

(3)./configure --disable-tcg --target-list=i386-softmmu
tcg is disabled in i386-softmmu

If the --target-list include other softmmus or user options, the configure command will report error and configure is aborted.
The error as:
ERROR: The current aarch64-softmmu can't support disable-tcg,
only i386-softmmu|x86_64-softmmu support disable-tcg
or
ERROR: The user build can't support disable-tcg,
only i386-softmmu|x86_64-softmmu support disable-tcg

---
 configure | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
configure +5 -0
index c571ad1..61ce514 100755
@@ -224,6 +224,7 @@ cap_ng=""
 attr=""
 libattr=""
 xfs=""
+tcg="yes"
 
 vhost_net="no"
 vhost_scsi="no"
@@ -953,6 +954,10 @@ for opt do
   ;;
   --enable-hax) hax="yes"
   ;;
+  --disable-tcg) tcg="no"
+  ;;
+  --enable-tcg) tcg="yes"
+  ;;
   --disable-tcg-interpreter) tcg_interpreter="no"
   ;;
   --enable-tcg-interpreter) tcg_interpreter="yes"
@@ -1715,6 +1720,24 @@ case " $target_list " in
   ;;
 esac
 

configure case " $target_list " in · line 1732

Quoted 10 lines
configure +10 -0
+if test "$tcg" = "no"; then
+   for target in $target_list; do
+      if test "$softmmu" = "yes"; then
+        case $target in
+           i386-softmmu|x86_64-softmmu)
+           ;;
+        *)
+           error_exit "The current $target can't support disable-tcg,"\
+              "only i386-softmmu|x86_64-softmmu support disable-tcg"
+           ;;

This looks too simplistic in its logic.

You can disable TCG, if-and-only-if the system emulator supports KVM.

KVM is supported on many architectures, not only x86-64 & i386.

KVM is only supported if the guest emulator architecture matches the host build target architecture.

ie if you are building an x86_64 system emulator on a PPC64 host, then you can't disable TCG.

So this needs rewriting to *not* special case x86_64 / i386. Instead you need to compare & match build target / system emulator architectures, across all architectures supporting KVM.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#3 lore raw

Re: [Qemu-devel] [PATCH v2 01/15] configure: add the disable-tcg option

Quoted 20 lines · Daniel P. Berrange

configure case " $target_list " in · line 1732

Quoted 11 lines
configure +10 -0
+if test "$tcg" = "no"; then
+   for target in $target_list; do
+      if test "$softmmu" = "yes"; then
+        case $target in
+           i386-softmmu|x86_64-softmmu)
+           ;;
+        *)
+           error_exit "The current $target can't support disable-tcg,"\
+              "only i386-softmmu|x86_64-softmmu support disable-tcg"
+           ;;

This looks too simplistic in its logic.

You can disable TCG, if-and-only-if the system emulator supports KVM.

KVM is supported on many architectures, not only x86-64 & i386.

KVM is only supported if the guest emulator architecture matches the host build target architecture.

Quoted 6 lines

ie if you are building an x86_64 system emulator on a PPC64 host, then you can't disable TCG.

So this needs rewriting to *not* special case x86_64 / i386. Instead you need to compare & match build target / system emulator architectures, across all architectures supporting KVM.

i386-softmmu and x86_64-softmmu are singled out here, because they're the only targets where --disable-tcg compiles. For the others, more work is needed (see patches 6-15 in Yang Zhong's series).

The part that is missing in this patch is disabling non-hypervisor targets when --disable-tcg is specified. My original patch built only i386-softmmu and x86_64-softmmu if you specified --disable-tcg, see

https://lists.nongnu.org/archive/html/qemu-devel/2012-09/msg02570.html
https://lists.nongnu.org/archive/html/qemu-devel/2012-09/msg02571.html

Paolo

#4 lore raw

Re: [Qemu-devel] [PATCH v2 01/15] configure: add the disable-tcg option

Quoted 26 lines · Paolo Bonzini
Quoted 23 lines · Daniel P. Berrange

configure case " $target_list " in · line 1732

Quoted 11 lines
configure +10 -0
+if test "$tcg" = "no"; then
+   for target in $target_list; do
+      if test "$softmmu" = "yes"; then
+        case $target in
+           i386-softmmu|x86_64-softmmu)
+           ;;
+        *)
+           error_exit "The current $target can't support disable-tcg,"\
+              "only i386-softmmu|x86_64-softmmu support disable-tcg"
+           ;;

This looks too simplistic in its logic.

You can disable TCG, if-and-only-if the system emulator supports KVM.

KVM is supported on many architectures, not only x86-64 & i386.

KVM is only supported if the guest emulator architecture matches the host build target architecture.

ie if you are building an x86_64 system emulator on a PPC64 host, then you can't disable TCG.

Quoted 7 lines
Quoted 3 lines

So this needs rewriting to *not* special case x86_64 / i386. Instead you need to compare & match build target / system emulator architectures, across all architectures supporting KVM.

i386-softmmu and x86_64-softmmu are singled out here, because they're the only targets where --disable-tcg compiles. For the others, more work is needed (see patches 6-15 in Yang Zhong's series).

Even with that, you still can't disable TCG if building on a non-x86 host, since that'd leave you with no available CPU at all. So the code still needs refactoring to check architectures properly.

Quoted 6 lines

The part that is missing in this patch is disabling non-hypervisor targets when --disable-tcg is specified. My original patch built only i386-softmmu and x86_64-softmmu if you specified --disable-tcg, see

https://lists.nongnu.org/archive/html/qemu-devel/2012-09/msg02570.html
https://lists.nongnu.org/archive/html/qemu-devel/2012-09/msg02571.html

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#5 lore raw

Re: [Qemu-devel] [PATCH v2 01/15] configure: add the disable-tcg option

Quoted 7 lines · Daniel P. Berrange
Quoted 3 lines

i386-softmmu and x86_64-softmmu are singled out here, because they're the only targets where --disable-tcg compiles. For the others, more work is needed (see patches 6-15 in Yang Zhong's series).

Even with that, you still can't disable TCG if building on a non-x86 host, since that'd leave you with no available CPU at all. So the code still needs refactoring to check architectures properly.

It would leave you with a tools-only build; whether that's a good idea, it's another story. I think it's acceptable, but others may disagree.

Paolo

Quoted 6 lines
Quoted 6 lines

The part that is missing in this patch is disabling non-hypervisor targets when --disable-tcg is specified. My original patch built only i386-softmmu and x86_64-softmmu if you specified --disable-tcg, see

https://lists.nongnu.org/archive/html/qemu-devel/2012-09/msg02570.html
https://lists.nongnu.org/archive/html/qemu-devel/2012-09/msg02571.html

#6 lore raw

Re: [Qemu-devel] [PATCH v2 01/15] configure: add the disable-tcg option

Quoted 7 lines · Paolo Bonzini
Quoted 4 lines · Daniel P. Berrange
Quoted 3 lines

i386-softmmu and x86_64-softmmu are singled out here, because they're the only targets where --disable-tcg compiles. For the others, more work is needed (see patches 6-15 in Yang Zhong's series).

Quoted 6 lines
Quoted 3 lines

Even with that, you still can't disable TCG if building on a non-x86 host, since that'd leave you with no available CPU at all. So the code still needs refactoring to check architectures properly.

It would leave you with a tools-only build; whether that's a good idea, it's another story. I think it's acceptable, but others may disagree.

I think this is OK for the first version. We still can refine the checks later if we then think that there is a need for it.

Thomas

#7 lore raw

Re: [Qemu-devel] [PATCH v2 01/15] configure: add the disable-tcg option

In reply to Paolo Bonzini
Quoted 7 lines · Paolo Bonzini
Quoted 4 lines · Daniel P. Berrange
Quoted 3 lines

i386-softmmu and x86_64-softmmu are singled out here, because they're the only targets where --disable-tcg compiles. For the others, more work is needed (see patches 6-15 in Yang Zhong's series).

Quoted 6 lines
Quoted 3 lines

Even with that, you still can't disable TCG if building on a non-x86 host, since that'd leave you with no available CPU at all. So the code still needs refactoring to check architectures properly.

It would leave you with a tools-only build; whether that's a good idea, it's another story. I think it's acceptable, but others may disagree.

If you do 'configure --target-list=x86_64-softmmu --disable-tcg' on a non-x86 host I would be surprised to find x86_64-softmmu not built. IMHO if you explicitly request system emulators and its not posisble to build then, an error should be report, rather than silently ignoring the request.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#10 lore raw

Re: [Qemu-devel] [PATCH v2 02/15] vl: add tcg_enabled() for tcg related code

In reply to Yang Zhong
Quoted 15 lines · Yang Zhong

Need to disable the tcg related code in the vl.c if the disable-tcg option is added into ./configure command.

---
 accel/tcg/tcg-all.c    |  2 +-
 include/sysemu/accel.h |  2 +-
 vl.c                   | 15 +++++++++++----
 3 files changed, 13 insertions(+), 6 deletions(-)
accel/tcg/tcg-all.c +0 -0
index dba9931..b86c896 100644

accel/tcg/tcg-all.c line 31

Quoted 5 lines
accel/tcg/tcg-all.c +1 -1
@@ -28,7 +28,7 @@
 #include "sysemu/sysemu.h"
 #include "qom/object.h"
 
-int tcg_tb_size;
+long tcg_tb_size;

This looks like a non-related change. I think you should either put it into a separate patch, or drop it.

Quoted 26 lines
accel/tcg/tcg-all.c +0 -0
 static bool tcg_allowed = true;
 
 static int tcg_init(MachineState *ms)
include/sysemu/accel.h +1 -1
index ecc5c84..7b905b7 100644
@@ -63,7 +63,7 @@ typedef struct AccelClass {
 #define ACCEL_GET_CLASS(obj) \
     OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL)
 
-extern int tcg_tb_size;
+extern long tcg_tb_size;
 
 void configure_accelerator(MachineState *ms);
 /* Register accelerator specific global properties */
vl.c +0 -2
index 36ff3f4..f28c1ac 100644
@@ -3933,9 +3933,14 @@ int main(int argc, char **argv, char **envp)
                 configure_rtc(opts);
                 break;
             case QEMU_OPTION_tb_size:
-                tcg_tb_size = strtol(optarg, NULL, 0);
-                if (tcg_tb_size < 0) {

vl.c int main(int argc, char **argv, char **envp) · line 3944

Quoted 10 lines
vl.c +8 -1
-                    tcg_tb_size = 0;
+                if (tcg_enabled()) {
+                    qemu_strtol(optarg, NULL, 0, &tcg_tb_size);
+                    if (tcg_tb_size < 0) {
+                        tcg_tb_size = 0;
+                    }
+                } else {
+                    error_report("TCG is disabled");
+                    exit(1);
                 }

You could do this without an else-part, leaving the tcg_tb_size code unmodified:

+ if (!tcg_enabled()) {
+ error_report("TCG is disabled");
+ exit(1);
+ }

                   tcg_tb_size = strtol(optarg, NULL, 0);
                   if (tcg_tb_size < 0) {
                       tcg_tb_size = 0;
Quoted 4 lines
vl.c +0 -0
                 break;
             case QEMU_OPTION_icount:

vl.c int main(int argc, char **argv, char **envp) · line 4494

Quoted 10 lines
vl.c +3 -1
@@ -4481,7 +4486,9 @@ int main(int argc, char **argv, char **envp)
         qemu_opts_del(icount_opts);
     }
 
-    qemu_tcg_configure(accel_opts, &error_fatal);
+    if (tcg_enabled()) {
+        qemu_tcg_configure(accel_opts, &error_fatal);
+    }
 
     if (default_net) {
         QemuOptsList *net = qemu_find_opts("net");

Thomas

#12 lore raw

Re: [Qemu-devel] [PATCH v2 03/15] tcg: tcg_handle_interrupt() function

In reply to Yang Zhong
Quoted 2 lines · Yang Zhong

Move tcg_handle_interrupt() from translate-common.c to accel/tcg/tcg-all.c.

Why is this necessary / wanted? Could you please mention the reason in the patch description?

Thanks,
Thomas

#8 lore raw

Re: [Qemu-devel] [PATCH v2 01/15] configure: add the disable-tcg option

In reply to Daniel P. Berrange
Quoted 7 lines · Daniel P. Berrange
Quoted 2 lines

It would leave you with a tools-only build; whether that's a good idea, it's another story. I think it's acceptable, but others may disagree.

If you do 'configure --target-list=x86_64-softmmu --disable-tcg' on a non-x86 host I would be surprised to find x86_64-softmmu not built. IMHO if you explicitly request system emulators and its not posisble to build then, an error should be report, rather than silently ignoring the request.

Technically you could build a qtest-only emulator, but I don't think _that_ is a good idea (and it's not what the patch does).

Paolo

#16 lore raw

Re: [Qemu-devel] [PATCH v2 06/15] kvmvapic: remove tcg related code

In reply to Yang Zhong
Quoted 3 lines · Yang Zhong

Since Paolo's below patch has fixed A20 issue
commit bbfa326fc8028e275eddf8c9965c2a1b59405b2e target/i386: enable A20 automatically in system management mod

How is this patch related to kvmvapic? It fixes a bug with vapic disabled, but it's not a reason to disable kvmvapic.

Paolo

Quoted 6 lines

The tcg code in kvmvapic.c is NOT useful, those code need remove.

---
 hw/i386/kvmvapic.c | 24 ------------------------
 1 file changed, 24 deletions(-)
author
#17 lore raw

Re: [Qemu-devel] [PATCH v2 06/15] kvmvapic: remove tcg related code

Quoted 12 lines · Paolo Bonzini
Quoted 3 lines · Yang Zhong

Since Paolo's below patch has fixed A20 issue
commit bbfa326fc8028e275eddf8c9965c2a1b59405b2e target/i386: enable A20 automatically in system management mod

How is this patch related to kvmvapic? It fixes a bug with vapic disabled, but it's not a reason to disable kvmvapic.

Paolo

Hello Paolo,

In that time, in order to verify the tcg code is not useful in kvmvapic.c file, we disabled the kvmvapic rom in the seabios and use the tcg accelator to boot guest image, we found this A20 bug.

Once this A20 bug has been fixed, we can use the tcg to bootup the guest image without kvmvapic rom, which show the tcg code in kvmvapic is not useful. This is reason why i removed the tcg code replace of using tcg_enabled() to check the tcg code in kvmvapic.c. thanks!

Regards,

Yang

Quoted 6 lines
Quoted 6 lines

The tcg code in kvmvapic.c is NOT useful, those code need remove.

---
 hw/i386/kvmvapic.c | 24 ------------------------
 1 file changed, 24 deletions(-)