hax: HAX is initialized more sophisticated way 63/30363/4
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 7 Nov 2014 05:58:19 +0000 (14:58 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 19 Nov 2014 06:24:34 +0000 (15:24 +0900)
Did not bother TCG initialization.
Removed redundant condition fields.(hax_disabled, hax_support)
Used small TB buffer for non-UG platform.

Change-Id: I6e0a9af12abf7e9399198440bc485f70453ce9c8
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
hax-stub.c
include/sysemu/hax.h
target-i386/hax-all.c
tizen/src/skin/maruskin_operation.c
vl.c

index 1ec5594..8620f5b 100644 (file)
 
 #include "sysemu/hax.h"
 
+bool hax_allowed;
+
 int hax_sync_vcpus(void)
 {
     return 0;
 }
 
-int hax_accel_init(void)
-{
-   return 0;
-}
-
-void hax_disable(int disable)
+int hax_accel_init(uint64_t ram_size)
 {
-   return;
-}
-
-int hax_pre_init(uint64_t ram_size)
-{
-   return 0;
-}
-
-int hax_enabled(void)
-{
-   return 0;
+   return -ENOSYS;
 }
 
 int hax_ug_platform(void)
 {
     return 0;
 }
-
index 1e97ad2..edece10 100644 (file)
 #include "config-host.h"
 #include "qemu-common.h"
 
+extern bool hax_allowed;
 
-// This needs to be fixed for vl.c, ich9.c, piix4.c.
-// Those files do not include config.h and will not have CONFIG_HAX defined.
-
-int hax_enabled(void);
-void hax_disable(int disable);
 int hax_ug_platform(void);
-int hax_pre_init(uint64_t ram_size);
-int hax_accel_init(void);
+int hax_accel_init(uint64_t ram_size);
 int hax_sync_vcpus(void);
 
+// called after hax_init
+#define hax_enabled()           hax_allowed
+
 #ifdef CONFIG_HAX
 
 #define dprint printf
index 05442ab..0ae34a7 100644 (file)
@@ -49,24 +49,12 @@ static int hax_handle_io(CPUArchState *env, uint32_t df, uint16_t port, int dir,
 static int hax_handle_fastmmio(CPUArchState *env, struct hax_fastmmio *hft);
 
 struct hax_state hax_global;
-int ret_hax_init = 0;
-static int hax_disabled = 1;
 
-int hax_support = -1;
 int ug_support = 0;
 
-/* Called after hax_init */
-int hax_enabled(void)
-{
-    return (!hax_disabled && hax_support);
-}
-
-void hax_disable(int disable)
-{
-    hax_disabled = disable;
-}
+bool hax_allowed;
 
-/* Called after hax_init */
+/* Called after hax_init_internal */
 int hax_ug_platform(void)
 {
     return (ug_support);
@@ -100,7 +88,7 @@ static int hax_stop_tbloop(CPUArchState *env)
     {
     case HAX_EMULATE_STATE_MMIO:
         if (cpu->hax_vcpu->resync) {
-            hax_prepare_emulation(env);     
+            hax_prepare_emulation(env);
             cpu->hax_vcpu->resync = 0;
             return 0;
         }
@@ -466,29 +454,12 @@ static void hax_handle_interrupt(CPUState *cpu, int mask)
     }
 }
 
-int hax_pre_init(uint64_t ram_size)
-{
-    struct hax_state *hax = NULL;
-
-    dprint("hax_disabled %d\n", hax_disabled);
-    if (hax_disabled)
-        return 0;
-    hax = &hax_global;
-    memset(hax, 0, sizeof(struct hax_state));
-    hax->mem_quota = ram_size;
-    dprint("ram_size %lx\n", ram_size);
-
-    return 0;
-}
-
-static int hax_init(void)
+static int hax_init_internal(void)
 {
     struct hax_state *hax = NULL;
     struct hax_qemu_version qversion;
     int ret;
 
-    hax_support = 0;
-
     hax = &hax_global;
 
 
@@ -531,7 +502,6 @@ static int hax_init(void)
     qversion.least_version = hax_lest_version;
     hax_notify_qemu_version(hax->vm->fd, &qversion);
     cpu_interrupt_handler = hax_handle_interrupt;
-    hax_support = 1;
 
     return ret;
 error:
@@ -543,23 +513,29 @@ error:
     return ret;
 }
 
-int hax_accel_init(void)
+int hax_accel_init(uint64_t ram_size)
 {
-    if (hax_disabled) {
-        dprint("HAX is disabled and emulator runs in emulation mode.\n");
-        return 0;
-    }
+    struct hax_state *hax = NULL;
+    int ret = 0;
+
+    hax = &hax_global;
+    memset(hax, 0, sizeof(struct hax_state));
+    hax->mem_quota = ram_size;
+    dprint("ram_size %lx\n", ram_size);
 
-    ret_hax_init = hax_init();
-    if (ret_hax_init && (ret_hax_init != -ENOSPC)) {
+    ret = hax_init_internal();
+    // It is better to fail than to transit implicitly.
+    /*
+    if (ret && (ret != -ENOSPC)) {
         dprint("No accelerator found.\n");
-        return ret_hax_init;
     } else {
         dprint("HAX is %s and emulator runs in %s mode.\n",
-        !ret_hax_init ? "working" : "not working",
-        !ret_hax_init ? "fast virt" : "emulation");
-        return 0;
+        !ret ? "working" : "not working",
+        !ret ? "fast virt" : "emulation");
     }
+    */
+
+    return ret;
 }
 
 static int hax_handle_fastmmio(CPUArchState *env, struct hax_fastmmio *hft)
index 0b55f96..ff2e389 100644 (file)
@@ -476,6 +476,7 @@ DetailInfo* get_detail_info(int qemu_argc, char** qemu_argv)
     hax_err_len = sprintf( hax_error + hax_err_len, "%s", "hax_error=" );
 
     int error = 0;
+// FIXME: ret_hax_init is no longer exist...
     if ( !ret_hax_init ) {
         if ( -ENOSPC == ret_hax_init ) {
             error = 1;
diff --git a/vl.c b/vl.c
index 2b6f1a6..98c3544 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -242,9 +242,6 @@ static NotifierList machine_init_done_notifiers =
 
 static bool tcg_allowed = true;
 bool xen_allowed;
-// FIXME: ??
-int hax_allowed = 0;
-//
 uint32_t xen_domid;
 enum xen_mode xen_mode = XEN_EMULATE;
 static int tcg_tb_size;
@@ -2746,10 +2743,18 @@ static MachineClass *machine_parse(const char *name)
 
 static int tcg_init(QEMUMachine *machine)
 {
-    int ret = 0;
-    ret = hax_accel_init();
-    if (!(hax_enabled() && hax_ug_platform()))
-        tcg_exec_init(tcg_tb_size * 1024 * 1024);
+    tcg_exec_init(tcg_tb_size * 1024 * 1024);
+    return 0;
+}
+
+static int hax_init(QEMUMachine *machine)
+{
+    int ret = hax_accel_init(ram_size);
+    if (!ret && !hax_ug_platform()) {
+        // TCG is used for very limited purpose under HAX.
+        // so we can allocate small TB buffer.
+        tcg_exec_init(16 * 1024 * 1024);
+    }
     return ret;
 }
 
@@ -2764,6 +2769,7 @@ static struct {
     { "xen", "Xen", xen_available, xen_init, &xen_allowed },
     { "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
     { "qtest", "QTest", qtest_available, qtest_init_accel, &qtest_allowed },
+    { "hax", "HAX", hax_available, hax_init, &hax_allowed },
 };
 
 static int configure_accelerator(QEMUMachine *machine)
@@ -3972,9 +3978,7 @@ int main(int argc, char **argv, char **envp)
                 break;
             case QEMU_OPTION_enable_hax:
                 olist = qemu_find_opts("machine");
-                //qemu_opts_reset(olist);
-                hax_disable(0);
-                //qemu_opts_parse(olist, "accel=hax", 0);
+                qemu_opts_parse(olist, "accel=hax", 0);
                 break;
             case QEMU_OPTION_add_fd:
 #ifndef _WIN32
@@ -4320,8 +4324,6 @@ int main(int argc, char **argv, char **envp)
         ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
     }
 
-    hax_pre_init(ram_size);
-
     if (qemu_opts_foreach(qemu_find_opts("device"), device_help_func, NULL, 0)
         != 0) {
         exit(0);