Skip to contentSkip to conversation

New shot at accelerators

PATCH Applied Glauber Costa 11 participants 80 messages Oct 23, 2008 – Oct 25, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

cover New shot at accelerators

Hi guys,

I'm sending here a new version of the accel patch. It comprises the cleaned up version I've last sent, plus a few additions

You may want to pay special attention to the additions, since they are newcomers to the series. To ease your job, they are:

0001-use-anonymous-memory-for-kqemu.patch 0002-protect-exec-all.h-frm-multiple-inclusion.patch 0003-change-definition-of-FILE-for-linux.patch 0005-use-more-meaningful-values-for-kqemu_cpu_exec.patch 0025-provide-accel-hook-for-cpu_exec.patch 0026-provide-two-accelerators-for-kqemu.patch 0027-arch-specific-hooks-for-accelerator.patch 0028-iret-arch-specific-accelerator.patch 0029-sysret-sysexit-arch-specific-accelerator.patch 0030-lcall-lret-arch-specific-accel-hooks.patch 0031-remove-kqemu_is_ok-tests.patch 0032-clean-up-kqemu-code.patch

git users can get a snapshot of it located at

git://git.kernel.org/pub/scm/virt/glommer/qemu-accel.git accel-v2

diffstat and OBP (One Big Patch ;-)) attached.

------

 Makefile.target         |    2 +-
 accel.c                 |   51 +++++++++
 accel.h                 |  171 ++++++++++++++++++++++++++++
 cpu-all.h               |    9 +-
 cpu-exec.c              |   47 +++-----
 dyngen-exec.h           |    6 +
 exec-all.h              |   34 +-----
 exec.c                  |  115 ++++++++++----------
 hw/pc.c                 |   13 +--
 kqemu.c                 |  284 +++++++++++++++++++++++++++++++++++++++++++----
 kqemu.h                 |   21 ++++
 monitor.c               |   70 +++++-------
 osdep.c                 |  111 ------------------
 softmmu_template.h      |   10 +-
 sysemu.h                |    5 -
 target-i386/accel86.h   |   60 ++++++++++
 target-i386/cpu.h       |   13 --
 target-i386/helper.c    |    8 +-
 target-i386/op_helper.c |   52 ++-------
 vl.c                    |   93 ++++++----------
 20 files changed, 736 insertions(+), 439 deletions(-)
Makefile.target +1 -1
index e2edf9d..623ecd8 100644
@@ -188,7 +188,7 @@ all: $(PROGS)
 #########################################################
 # cpu emulator library
 LIBOBJS=exec.o kqemu.o translate-all.o cpu-exec.o\
-        translate.o host-utils.o
+        translate.o host-utils.o accel.o
 ifdef CONFIG_DYNGEN_OP
 exec.o: dyngen-opc.h
 LIBOBJS+=op.o
accel.c new file +51 -0

51 lines not on this page · raw message

accel.h new file +171 -0

171 lines not on this page · raw message

cpu-all.h +4 -5
index cdd79bc..edefb45 100644
@@ -863,6 +863,10 @@ extern ram_addr_t ram_size;
 typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
 typedef uint32_t CPUReadMemoryFunc(void *opaque, target_phys_addr_t addr);
 
+/* this is a private version, meant for internal use of accelerators */
+void __cpu_register_physical_memory(target_phys_addr_t start_addr,
+                                  ram_addr_t size,
+                                  ram_addr_t phys_offset);
 void cpu_register_physical_memory(target_phys_addr_t start_addr,
                                   ram_addr_t size,
                                   ram_addr_t phys_offset);
@@ -1077,14 +1081,9 @@ static inline int64_t profile_getclock(void)
     return cpu_get_real_ticks();
 }
 
-extern int64_t kqemu_time, kqemu_time_start;
 extern int64_t qemu_time, qemu_time_start;
 extern int64_t tlb_flush_time;
-extern int64_t kqemu_exec_count;
 extern int64_t dev_time;
-extern int64_t kqemu_ret_int_count;
-extern int64_t kqemu_ret_excp_count;
-extern int64_t kqemu_ret_intr_count;
 #endif
 
 #endif /* CPU_ALL_H */
cpu-exec.c +17 -30

74 lines not on this page · raw message

dyngen-exec.h +6 -0
index 9260b6f..826ff46 100644
@@ -27,6 +27,10 @@
 #define _FILEDEFED
 #endif
 
+#ifdef __linux__
+#define __FILE_defined
+#endif
+
 /* NOTE: standard headers should be used with special care at this
    point because host CPU registers are used as global variables. Some
    host headers do not allow that. */
@@ -84,6 +88,8 @@ typedef void * host_reg_t;
 
 #ifdef _BSD
 typedef struct __sFILE FILE;
+#elif defined(__linux__)
+typedef struct _IO_FILE FILE;
 #else
 typedef struct FILE FILE;
 #endif
exec-all.h +5 -29
index 6609c9a..fa4a4eb 100644
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#ifndef _EXEC_ALL_H_
+#define _EXEC_ALL_H_
 /* allow to see translation results - the slowdown should be negligible, so we leave it */
 #define DEBUG_DISAS
 
@@ -354,34 +356,8 @@ static inline int can_do_io(CPUState *env)
 }
 #endif
 
-#ifdef USE_KQEMU
-#define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))
-
-#define MSR_QPI_COMMBASE 0xfabe0010
-
-int kqemu_init(CPUState *env);
-int kqemu_cpu_exec(CPUState *env);
-void kqemu_flush_page(CPUState *env, target_ulong addr);
-void kqemu_flush(CPUState *env, int global);
-void kqemu_set_notdirty(CPUState *env, ram_addr_t ram_addr);
-void kqemu_modify_page(CPUState *env, ram_addr_t ram_addr);
-void kqemu_set_phys_mem(uint64_t start_addr, ram_addr_t size, 
-                        ram_addr_t phys_offset);
-void kqemu_cpu_interrupt(CPUState *env);
-void kqemu_record_dump(void);
-
-extern uint32_t kqemu_comm_base;
-
-static inline int kqemu_is_ok(CPUState *env)
-{
-    return(env->kqemu_enabled &&
-           (env->cr[0] & CR0_PE_MASK) &&
-           !(env->hflags & HF_INHIBIT_IRQ_MASK) &&
-           (env->eflags & IF_MASK) &&
-           !(env->eflags & VM_MASK) &&
-           (env->kqemu_enabled == 2 ||
-            ((env->hflags & HF_CPL_MASK) == 3 &&
-             (env->eflags & IOPL_MASK) != IOPL_MASK)));
-}
+#define EXEC_EXIT_DONE 0
+#define EXEC_EXIT_INTR 1
+#define EXEC_EXIT_SOFTMMU 2
 
 #endif
exec.c +58 -57

202 lines not on this page · raw message

hw/pc.c +2 -11
index 34683e7..2f56c1f 100644
@@ -33,6 +33,7 @@
 #include "boards.h"
 #include "console.h"
 #include "fw_cfg.h"
+#include "accel.h"
 
 /* output Bochs bios info messages */
 //#define DEBUG_BIOS
@@ -75,17 +76,7 @@ static void ioportF0_write(void *opaque, uint32_t addr, uint32_t data)
 /* TSC handling */
 uint64_t cpu_get_tsc(CPUX86State *env)
 {
-    /* Note: when using kqemu, it is more logical to return the host TSC
-       because kqemu does not trap the RDTSC instruction for
-       performance reasons */
-#ifdef USE_KQEMU
-    if (env->kqemu_enabled) {
-        return cpu_get_real_ticks();
-    } else
-#endif
-    {
-        return cpu_get_ticks();
-    }
+    return accel_get_real_ticks();
 }
 
 /* SMM support */
kqemu.c +262 -22

417 lines not on this page · raw message

kqemu.h +21 -0
index ed25c75..4152fbd 100644
@@ -32,6 +32,12 @@
 
 #define KQEMU_VERSION 0x010400
 
+extern int64_t kqemu_time, kqemu_time_start;
+extern int64_t kqemu_exec_count;
+extern int64_t kqemu_ret_int_count;
+extern int64_t kqemu_ret_excp_count;
+extern int64_t kqemu_ret_intr_count;
+
 struct kqemu_segment_cache {
     uint16_t selector;
     uint16_t padding1;
@@ -151,4 +157,19 @@ struct kqemu_phys_mem {
 #define KQEMU_SET_PHYS_MEM     _IOW('q', 5, struct kqemu_phys_mem)
 #endif
 
+int kqemu_is_enabled(CPUState *env);
+int kqemu_kernel_enabled(CPUState *env);
+
+typedef struct KQEMUCPUstate {
+    int last_io_time;
+    CPUState env;
+} KQEMUCPUState;
+
+#define kqemu_cpu_field(env, field) (*({ \
+    KQEMUCPUState *__c = container_of(env, KQEMUCPUState, env); \
+    &__c->field; }))
+
+#define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))
+
+#define MSR_QPI_COMMBASE 0xfabe0010
 #endif /* KQEMU_H */
monitor.c +26 -44

113 lines not on this page · raw message

osdep.c +0 -111

132 lines not on this page · raw message

softmmu_template.h +4 -6
index 98dd378..4945352 100644
@@ -47,6 +47,8 @@
 #define ADDR_READ addr_read
 #endif
 
+#include "accel.h"
+
 static DATA_TYPE glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(target_ulong addr,
                                                         int mmu_idx,
                                                         void *retaddr);
@@ -75,9 +77,7 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(target_phys_addr_t physaddr,
     res |= (uint64_t)io_mem_read[index][2](io_mem_opaque[index], physaddr + 4) << 32;
 #endif
 #endif /* SHIFT > 2 */
-#ifdef USE_KQEMU
-    env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
     return res;
 }
 
@@ -220,9 +220,7 @@ static inline void glue(io_write, SUFFIX)(target_phys_addr_t physaddr,
     io_mem_write[index][2](io_mem_opaque[index], physaddr + 4, val >> 32);
 #endif
 #endif /* SHIFT > 2 */
-#ifdef USE_KQEMU
-    env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
 }
 
 void REGPARM glue(glue(__st, SUFFIX), MMUSUFFIX)(target_ulong addr,
sysemu.h +0 -5
index 976fecc..5a19626 100644
@@ -99,11 +99,6 @@ extern int semihosting_enabled;
 extern int old_param;
 extern const char *bootp_filename;
 
-
-#ifdef USE_KQEMU
-extern int kqemu_allowed;
-#endif
-
 #define MAX_OPTION_ROMS 16
 extern const char *option_rom[MAX_OPTION_ROMS];
 extern int nb_option_roms;
target-i386/accel86.h new file +60 -0

60 lines not on this page · raw message

target-i386/cpu.h +0 -13
index 3c11e0f..e5e91cc 100644
@@ -606,10 +606,6 @@ typedef struct CPUX86State {
     uint32_t cpuid_ext3_features;
     uint32_t cpuid_apic_id;
 
-#ifdef USE_KQEMU
-    int kqemu_enabled;
-    int last_io_time;
-#endif
     /* in order to simplify APIC support, we leave this pointer to the
        user */
     struct APICState *apic_state;
@@ -727,15 +723,6 @@ void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0);
 #define X86_DUMP_FPU  0x0001 /* dump FPU state too */
 #define X86_DUMP_CCOP 0x0002 /* dump qemu flag cache */
 
-#ifdef USE_KQEMU
-static inline int cpu_get_time_fast(void)
-{
-    int low, high;
-    asm volatile("rdtsc" : "=a" (low), "=d" (high));
-    return low;
-}
-#endif
-
 #define TARGET_PAGE_BITS 12
 
 #define CPUState CPUX86State
target-i386/helper.c +4 -4
index c2e1a88..5ff051f 100644
@@ -30,6 +30,8 @@
 #include "svm.h"
 #include "qemu-common.h"
 
+#include "accel.h"
+
 //#define DEBUG_MMU
 
 static int cpu_x86_register (CPUX86State *env, const char *cpu_model);
@@ -96,7 +98,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
     CPUX86State *env;
     static int inited;
 
-    env = qemu_mallocz(sizeof(CPUX86State));
+    env = accel_get_env();
     if (!env)
         return NULL;
     cpu_exec_init(env);
@@ -112,9 +114,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
         return NULL;
     }
     cpu_reset(env);
-#ifdef USE_KQEMU
-    kqemu_init(env);
-#endif
+    accel_init_env(env);
     return env;
 }
 
target-i386/op_helper.c +8 -44

94 lines not on this page · raw message

vl.c +36 -57

203 lines not on this page · raw message

#1 lore raw

PATCH 1/32 use anonymous memory for kqemu.

---
 osdep.c |  111 ---------------------------------------------------------------
 1 files changed, 0 insertions(+), 111 deletions(-)
osdep.c +0 -111
index 683aad0..31c96e6 100644
@@ -68,112 +68,9 @@ void qemu_vfree(void *ptr)
 
 #else
 
-#if defined(USE_KQEMU)
-
-#ifdef __OpenBSD__
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/mount.h>
-#else
-#include <sys/vfs.h>
-#endif
-
 #include <sys/mman.h>
 #include <fcntl.h>
 
-static void *kqemu_vmalloc(size_t size)
-{
-    static int phys_ram_fd = -1;
-    static int phys_ram_size = 0;
-    void *ptr;
-
-#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */
-    int map_anon = MAP_ANON;
-#else
-    int map_anon = 0;
-    const char *tmpdir;
-    char phys_ram_file[1024];
-#ifdef HOST_SOLARIS
-    struct statvfs stfs;
-#else
-    struct statfs stfs;
-#endif
-
-    if (phys_ram_fd < 0) {
-        tmpdir = getenv("QEMU_TMPDIR");
-        if (!tmpdir)
-#ifdef HOST_SOLARIS
-            tmpdir = "/tmp";
-        if (statvfs(tmpdir, &stfs) == 0) {
-#else
-            tmpdir = "/dev/shm";
-        if (statfs(tmpdir, &stfs) == 0) {
-#endif
-            int64_t free_space;
-            int ram_mb;
-
-            free_space = (int64_t)stfs.f_bavail * stfs.f_bsize;
-            if ((ram_size + 8192 * 1024) >= free_space) {
-                ram_mb = (ram_size / (1024 * 1024));
-                fprintf(stderr,
-                        "You do not have enough space in '%s' for the %d MB of QEMU virtual RAM.\n",
-                        tmpdir, ram_mb);
-                if (strcmp(tmpdir, "/dev/shm") == 0) {
-                    fprintf(stderr, "To have more space available provided you have enough RAM and swap, do as root:\n"
-                            "mount -o remount,size=%dm /dev/shm\n",
-                            ram_mb + 16);
-                } else {
-                    fprintf(stderr,
-                            "Use the '-m' option of QEMU to diminish the amount of virtual RAM or use the\n"
-                            "QEMU_TMPDIR environment variable to set another directory where the QEMU\n"
-                            "temporary RAM file will be opened.\n");
-                }
-                fprintf(stderr, "Or disable the accelerator module with -no-kqemu\n");
-                exit(1);
-            }
-        }
-        snprintf(phys_ram_file, sizeof(phys_ram_file), "%s/qemuXXXXXX",
-                 tmpdir);
-        phys_ram_fd = mkstemp(phys_ram_file);
-        if (phys_ram_fd < 0) {
-            fprintf(stderr,
-                    "warning: could not create temporary file in '%s'.\n"
-                    "Use QEMU_TMPDIR to select a directory in a tmpfs filesystem.\n"
-                    "Using '/tmp' as fallback.\n",
-                    tmpdir);
-            snprintf(phys_ram_file, sizeof(phys_ram_file), "%s/qemuXXXXXX",
-                     "/tmp");
-            phys_ram_fd = mkstemp(phys_ram_file);
-            if (phys_ram_fd < 0) {
-                fprintf(stderr, "Could not create temporary memory file '%s'\n",
-                        phys_ram_file);
-                exit(1);
-            }
-        }
-        unlink(phys_ram_file);
-    }
-    size = (size + 4095) & ~4095;
-    ftruncate(phys_ram_fd, phys_ram_size + size);
-#endif /* !__OpenBSD__ */
-    ptr = mmap(NULL,
-               size,
-               PROT_WRITE | PROT_READ, map_anon | MAP_SHARED,
-               phys_ram_fd, phys_ram_size);
-    if (ptr == MAP_FAILED) {
-        fprintf(stderr, "Could not map physical memory\n");
-        exit(1);
-    }
-    phys_ram_size += size;
-    return ptr;
-}
-
-static void kqemu_vfree(void *ptr)
-{
-    /* may be useful some day, but currently we do not need to free */
-}
-
-#endif
-
 void *qemu_memalign(size_t alignment, size_t size)
 {
 #if defined(_POSIX_C_SOURCE)
@@ -193,10 +90,6 @@ void *qemu_memalign(size_t alignment, size_t size)
 /* alloc shared memory pages */
 void *qemu_vmalloc(size_t size)
 {
-#if defined(USE_KQEMU)
-    if (kqemu_allowed)
-        return kqemu_vmalloc(size);
-#endif
 #ifdef _BSD
     return valloc(size);
 #else
@@ -206,10 +99,6 @@ void *qemu_vmalloc(size_t size)
 
 void qemu_vfree(void *ptr)
 {
-#if defined(USE_KQEMU)
-    if (kqemu_allowed)
-        kqemu_vfree(ptr);
-#endif
     free(ptr);
 }
 
Signature · 1 line
1.5.5.1
#2 lore raw

[Qemu-devel] Re: [PATCH 01/32] use anonymous memory for kqemu.

Quoted 1 line · Glauber Costa

-ENOREASON

What was the original idea behind using a named mem region? Why is it no longer needed? Maybe I missed that point on the list, but then it would still be nice-to-have in the changelog.

Quoted 133 lines
---
 osdep.c |  111 ---------------------------------------------------------------
 1 files changed, 0 insertions(+), 111 deletions(-)
osdep.c +0 -107
index 683aad0..31c96e6 100644
@@ -68,112 +68,9 @@ void qemu_vfree(void *ptr)
 
 #else
 
-#if defined(USE_KQEMU)
-
-#ifdef __OpenBSD__
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/mount.h>
-#else
-#include <sys/vfs.h>
-#endif
-
 #include <sys/mman.h>
 #include <fcntl.h>
 
-static void *kqemu_vmalloc(size_t size)
-{
-    static int phys_ram_fd = -1;
-    static int phys_ram_size = 0;
-    void *ptr;
-
-#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */
-    int map_anon = MAP_ANON;
-#else
-    int map_anon = 0;
-    const char *tmpdir;
-    char phys_ram_file[1024];
-#ifdef HOST_SOLARIS
-    struct statvfs stfs;
-#else
-    struct statfs stfs;
-#endif
-
-    if (phys_ram_fd < 0) {
-        tmpdir = getenv("QEMU_TMPDIR");
-        if (!tmpdir)
-#ifdef HOST_SOLARIS
-            tmpdir = "/tmp";
-        if (statvfs(tmpdir, &stfs) == 0) {
-#else
-            tmpdir = "/dev/shm";
-        if (statfs(tmpdir, &stfs) == 0) {
-#endif
-            int64_t free_space;
-            int ram_mb;
-
-            free_space = (int64_t)stfs.f_bavail * stfs.f_bsize;
-            if ((ram_size + 8192 * 1024) >= free_space) {
-                ram_mb = (ram_size / (1024 * 1024));
-                fprintf(stderr,
-                        "You do not have enough space in '%s' for the %d MB of QEMU virtual RAM.\n",
-                        tmpdir, ram_mb);
-                if (strcmp(tmpdir, "/dev/shm") == 0) {
-                    fprintf(stderr, "To have more space available provided you have enough RAM and swap, do as root:\n"
-                            "mount -o remount,size=%dm /dev/shm\n",
-                            ram_mb + 16);
-                } else {
-                    fprintf(stderr,
-                            "Use the '-m' option of QEMU to diminish the amount of virtual RAM or use the\n"
-                            "QEMU_TMPDIR environment variable to set another directory where the QEMU\n"
-                            "temporary RAM file will be opened.\n");
-                }
-                fprintf(stderr, "Or disable the accelerator module with -no-kqemu\n");
-                exit(1);
-            }
-        }
-        snprintf(phys_ram_file, sizeof(phys_ram_file), "%s/qemuXXXXXX",
-                 tmpdir);
-        phys_ram_fd = mkstemp(phys_ram_file);
-        if (phys_ram_fd < 0) {
-            fprintf(stderr,
-                    "warning: could not create temporary file in '%s'.\n"
-                    "Use QEMU_TMPDIR to select a directory in a tmpfs filesystem.\n"
-                    "Using '/tmp' as fallback.\n",
-                    tmpdir);
-            snprintf(phys_ram_file, sizeof(phys_ram_file), "%s/qemuXXXXXX",
-                     "/tmp");
-            phys_ram_fd = mkstemp(phys_ram_file);
-            if (phys_ram_fd < 0) {
-                fprintf(stderr, "Could not create temporary memory file '%s'\n",
-                        phys_ram_file);
-                exit(1);
-            }
-        }
-        unlink(phys_ram_file);
-    }
-    size = (size + 4095) & ~4095;
-    ftruncate(phys_ram_fd, phys_ram_size + size);
-#endif /* !__OpenBSD__ */
-    ptr = mmap(NULL,
-               size,
-               PROT_WRITE | PROT_READ, map_anon | MAP_SHARED,
-               phys_ram_fd, phys_ram_size);
-    if (ptr == MAP_FAILED) {
-        fprintf(stderr, "Could not map physical memory\n");
-        exit(1);
-    }
-    phys_ram_size += size;
-    return ptr;
-}
-
-static void kqemu_vfree(void *ptr)
-{
-    /* may be useful some day, but currently we do not need to free */
-}
-
-#endif
-
 void *qemu_memalign(size_t alignment, size_t size)
 {
 #if defined(_POSIX_C_SOURCE)
@@ -193,10 +90,6 @@ void *qemu_memalign(size_t alignment, size_t size)
 /* alloc shared memory pages */
 void *qemu_vmalloc(size_t size)
 {
-#if defined(USE_KQEMU)
-    if (kqemu_allowed)
-        return kqemu_vmalloc(size);
-#endif
 #ifdef _BSD
     return valloc(size);
 #else

osdep.c void *qemu_vmalloc(size_t size) · line 104

Quoted 10 lines
osdep.c +0 -4
@@ -206,10 +99,6 @@ void *qemu_vmalloc(size_t size)
 
 void qemu_vfree(void *ptr)
 {
-#if defined(USE_KQEMU)
-    if (kqemu_allowed)
-        kqemu_vfree(ptr);
-#endif
     free(ptr);
 }
 

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#3 lore raw

[Qemu-devel] Re: [PATCH 01/32] use anonymous memory for kqemu.

In reply to Glauber Costa

The idea behind this patch is that currently kqemu uses /dev/shm for memory allocations instead of anonymous memory (like the rest of QEMU). Instead of introducing YA hook, we can just switch kqemu to use anonymous memory and eliminate the special case.

If I recall correctly, the reason for using /dev/shm was concern that get_user_pages() didn't do the right thing for anonymous memory and the use of /dev/shm was a hack around that. However, I'm not sure that was ever the case. Certainly, with any sufficiently modern kernel get_user_pages() does what one would expect. KVM uses get_user_pages() on anonymous memory in roughly the same way kqemu uses it now.

So I think it's safe to make the switch. Fabrice, what do you think?

Regards,

Anthony Liguori

Quoted 145 lines · Glauber Costa
---
 osdep.c |  111 ---------------------------------------------------------------
 1 files changed, 0 insertions(+), 111 deletions(-)
osdep.c +0 -111
index 683aad0..31c96e6 100644
@@ -68,112 +68,9 @@ void qemu_vfree(void *ptr)
 
 #else
 
-#if defined(USE_KQEMU)
-
-#ifdef __OpenBSD__
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/mount.h>
-#else
-#include <sys/vfs.h>
-#endif
-
 #include <sys/mman.h>
 #include <fcntl.h>
 
-static void *kqemu_vmalloc(size_t size)
-{
-    static int phys_ram_fd = -1;
-    static int phys_ram_size = 0;
-    void *ptr;
-
-#ifdef __OpenBSD__ /* no need (?) for a dummy file on OpenBSD */
-    int map_anon = MAP_ANON;
-#else
-    int map_anon = 0;
-    const char *tmpdir;
-    char phys_ram_file[1024];
-#ifdef HOST_SOLARIS
-    struct statvfs stfs;
-#else
-    struct statfs stfs;
-#endif
-
-    if (phys_ram_fd < 0) {
-        tmpdir = getenv("QEMU_TMPDIR");
-        if (!tmpdir)
-#ifdef HOST_SOLARIS
-            tmpdir = "/tmp";
-        if (statvfs(tmpdir, &stfs) == 0) {
-#else
-            tmpdir = "/dev/shm";
-        if (statfs(tmpdir, &stfs) == 0) {
-#endif
-            int64_t free_space;
-            int ram_mb;
-
-            free_space = (int64_t)stfs.f_bavail * stfs.f_bsize;
-            if ((ram_size + 8192 * 1024) >= free_space) {
-                ram_mb = (ram_size / (1024 * 1024));
-                fprintf(stderr,
-                        "You do not have enough space in '%s' for the %d MB of QEMU virtual RAM.\n",
-                        tmpdir, ram_mb);
-                if (strcmp(tmpdir, "/dev/shm") == 0) {
-                    fprintf(stderr, "To have more space available provided you have enough RAM and swap, do as root:\n"
-                            "mount -o remount,size=%dm /dev/shm\n",
-                            ram_mb + 16);
-                } else {
-                    fprintf(stderr,
-                            "Use the '-m' option of QEMU to diminish the amount of virtual RAM or use the\n"
-                            "QEMU_TMPDIR environment variable to set another directory where the QEMU\n"
-                            "temporary RAM file will be opened.\n");
-                }
-                fprintf(stderr, "Or disable the accelerator module with -no-kqemu\n");
-                exit(1);
-            }
-        }
-        snprintf(phys_ram_file, sizeof(phys_ram_file), "%s/qemuXXXXXX",
-                 tmpdir);
-        phys_ram_fd = mkstemp(phys_ram_file);
-        if (phys_ram_fd < 0) {
-            fprintf(stderr,
-                    "warning: could not create temporary file in '%s'.\n"
-                    "Use QEMU_TMPDIR to select a directory in a tmpfs filesystem.\n"
-                    "Using '/tmp' as fallback.\n",
-                    tmpdir);
-            snprintf(phys_ram_file, sizeof(phys_ram_file), "%s/qemuXXXXXX",
-                     "/tmp");
-            phys_ram_fd = mkstemp(phys_ram_file);
-            if (phys_ram_fd < 0) {
-                fprintf(stderr, "Could not create temporary memory file '%s'\n",
-                        phys_ram_file);
-                exit(1);
-            }
-        }
-        unlink(phys_ram_file);
-    }
-    size = (size + 4095) & ~4095;
-    ftruncate(phys_ram_fd, phys_ram_size + size);
-#endif /* !__OpenBSD__ */
-    ptr = mmap(NULL,
-               size,
-               PROT_WRITE | PROT_READ, map_anon | MAP_SHARED,
-               phys_ram_fd, phys_ram_size);
-    if (ptr == MAP_FAILED) {
-        fprintf(stderr, "Could not map physical memory\n");
-        exit(1);
-    }
-    phys_ram_size += size;
-    return ptr;
-}
-
-static void kqemu_vfree(void *ptr)
-{
-    /* may be useful some day, but currently we do not need to free */
-}
-
-#endif
-
 void *qemu_memalign(size_t alignment, size_t size)
 {
 #if defined(_POSIX_C_SOURCE)
@@ -193,10 +90,6 @@ void *qemu_memalign(size_t alignment, size_t size)
 /* alloc shared memory pages */
 void *qemu_vmalloc(size_t size)
 {
-#if defined(USE_KQEMU)
-    if (kqemu_allowed)
-        return kqemu_vmalloc(size);
-#endif
 #ifdef _BSD
     return valloc(size);
 #else
@@ -206,10 +99,6 @@ void *qemu_vmalloc(size_t size)
 
 void qemu_vfree(void *ptr)
 {
-#if defined(USE_KQEMU)
-    if (kqemu_allowed)
-        kqemu_vfree(ptr);
-#endif
     free(ptr);
 }
 
#4 lore raw

[Qemu-devel] Re: [PATCH 01/32] use anonymous memory for kqemu.

Quoted 5 lines · Anthony Liguori

The idea behind this patch is that currently kqemu uses /dev/shm for memory allocations instead of anonymous memory (like the rest of QEMU). Instead of introducing YA hook, we can just switch kqemu to use anonymous memory and eliminate the special case.

Quoted 8 lines

If I recall correctly, the reason for using /dev/shm was concern that get_user_pages() didn't do the right thing for anonymous memory and the use of /dev/shm was a hack around that. However, I'm not sure that was ever the case. Certainly, with any sufficiently modern kernel get_user_pages() does what one would expect. KVM uses get_user_pages() on anonymous memory in roughly the same way kqemu uses it now.

So I think it's safe to make the switch. Fabrice, what do you think?

This hack-around, was it purely Linux-motivated? Or did/do other OSes have similar issues?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#5 lore raw

[Qemu-devel] Re: [PATCH 01/32] use anonymous memory for kqemu.

Quoted 13 lines · Jan Kiszka
Quoted 11 lines · Anthony Liguori

The idea behind this patch is that currently kqemu uses /dev/shm for
memory allocations instead of anonymous memory (like the rest of QEMU). Instead of introducing YA hook, we can just switch kqemu to use anonymous memory and eliminate the special case.

If I recall correctly, the reason for using /dev/shm was concern that get_user_pages() didn't do the right thing for anonymous memory and the use of /dev/shm was a hack around that. However, I'm not sure that was ever the case. Certainly, with any sufficiently modern kernel get_user_pages() does what one would expect. KVM uses get_user_pages() on anonymous memory in roughly the same way kqemu uses it now.

Quoted 6 lines
Quoted 2 lines

So I think it's safe to make the switch. Fabrice, what do you think?

This hack-around, was it purely Linux-motivated? Or did/do other OSes have similar issues?

/dev/shm doesn't exist on anything but Linux.

Regards,

Anthony Liguori

Quoted 3 lines

Jan

#6 lore raw

Re: [Qemu-devel] Re: [PATCH 01/32] use anonymous memory for kqemu.

Quoted 6 lines · Anthony Liguori
Quoted 4 lines · Jan Kiszka

This hack-around, was it purely Linux-motivated? Or did/do other OSes have similar issues?

Quoted 7 lines

/dev/shm doesn't exist on anything but Linux.

Regards,

Anthony Liguori

Quoted 1 line

Jan

This should be tested well on Solaris 10, especially with -m values approaching 1GB and -kernel-kqemu. The Solaris version would use /tmp rather than /dev/shm, but iirc there were problems when using MAP_ANONYMOUS.

Also, on Linux, does anyone know what minimum kernel version is needed to not need the /dev/shm hack?

Thanks,

Leo Reiter

#7 lore raw

Re: [Qemu-devel] Re: [PATCH 01/32] use anonymous memory for kqemu.

Quoted 8 lines · Leonardo Reiter

This should be tested well on Solaris 10, especially with -m values approaching 1GB and -kernel-kqemu. The Solaris version would use /tmp rather than /dev/shm, but iirc there were problems when using MAP_ANONYMOUS.

Also, on Linux, does anyone know what minimum kernel version is needed to not need the /dev/shm hack?

Please disregard the Solaris bit as the 1.4.0 version of KQEMU is not widely available there yet, so you can't use the SVN version of QEMU with KQEMU anyway AFAIK. I'd be glad to look at this in the (somewhat distant) future and come up with a patch if anonymous memory on Solaris is not stable.

But the Linux bit is still good to understand. I know Fabrice put this limitation in specifically because of problems with Linux kernels, so it would be good to know what minimum kernel version seems to have this fixed.

Thanks,

Leo Reiter

#8 lore raw

Re: [Qemu-devel] Re: [PATCH 01/32] use anonymous memory for kqemu.

Am 23.10.2008 um 17:20 schrieb Leonardo Reiter:

Quoted 6 lines · Leonardo Reiter
Quoted 5 lines

This should be tested well on Solaris 10, especially with -m values approaching 1GB and -kernel-kqemu. The Solaris version would use /tmp rather than /dev/shm, but iirc there were problems when using MAP_ANONYMOUS.

Quoted 8 lines
Quoted 3 lines

Also, on Linux, does anyone know what minimum kernel version is needed to not need the /dev/shm hack?

Please disregard the Solaris bit as the 1.4.0 version of KQEMU is not widely available there yet, so you can't use the SVN version of QEMU with KQEMU anyway AFAIK. I'd be glad to look at this in the (somewhat distant) future and come up with a patch if anonymous memory on Solaris is not stable.

OpenSolaris.org has a kqemu version that I've been happily using there with SVN. It supposedly supports Solaris 9 and 8, so by inference 10 as well, I'd hope.
http://www.opensolaris.org/os/project/qemu/downloads/

Last time I heard it wasn't merged upstream, so it would be good to check how well the Solaris (and FreeBSD?) kqemu variants work with this series. Maybe merge into the current codebase before making too much assumptions for the new accel interface?

Andreas

#9 lore raw

Re: [Qemu-devel] Re: [PATCH 01/32] use anonymous memory for kqemu.

Quoted 20 lines · Andreas Färber

Am 23.10.2008 um 17:20 schrieb Leonardo Reiter:

Quoted 8 lines
Quoted 6 lines · Leonardo Reiter

This should be tested well on Solaris 10, especially with -m values approaching 1GB and -kernel-kqemu. The Solaris version would use /tmp rather than /dev/shm, but iirc there were problems when using MAP_ANONYMOUS.

Quoted 8 lines
Quoted 3 lines

Also, on Linux, does anyone know what minimum kernel version is needed to not need the /dev/shm hack?

Please disregard the Solaris bit as the 1.4.0 version of KQEMU is not widely available there yet, so you can't use the SVN version of QEMU with KQEMU anyway AFAIK. I'd be glad to look at this in the (somewhat distant) future and come up with a patch if anonymous memory on Solaris is not stable.

Quoted 4 lines

OpenSolaris.org has a kqemu version that I've been happily using there with SVN. It supposedly supports Solaris 9 and 8, so by inference 10 as well, I'd hope.
http://www.opensolaris.org/os/project/qemu/downloads/

There are currently two versions. 1.3.0pre11 works with Solaris 9, 10 and SXCE. 8 should work, but there are differences in the calls used in kqemu depending on which kernel version of Solaris you're running. that will work with any svn up to the introduction of the 1.4.0 kqemu module.

I also ported 1.4.0pre1, and Juergen Keil and a Sun engineer found a couple of bugs that should be squashed now.

However, the big problem I see is that the addition of c99 features borks a qemu compile on Solaris, specfically around stdbool.h. Turning on -std=c99 or -std=gnuc99 creates more problems because gcc-3.4.3 provided by solaris doesn't accept the anonymous unions that are prevalent around the new code, specifically nbd and vnc.

Quoted 5 lines

Last time I heard it wasn't merged upstream, so it would be good to check how well the Solaris (and FreeBSD?) kqemu variants work with this series. Maybe merge into the current codebase before making too much assumptions for the new accel interface?

I'll give it a whirl.

Ben

#10 lore raw

[Qemu-devel] QEMU on Solaris 10 (was: [PATCH 01/32] use anonymous memory for kqemu.)

Am 24.10.2008 um 21:59 schrieb Ben Taylor:

Quoted 5 lines

the big problem I see is that the addition of c99 features borks a qemu compile on Solaris, specfically around stdbool.h. Turning on -std=c99 or -std=gnuc99 creates more problems because gcc-3.4.3 provided by solaris doesn't accept the anonymous unions that are prevalent around the new code, specifically nbd and vnc.

I just gave it a try on S10 5/08 amd64, using the gcc 3.4.3 from Sun and --disable-gcc-check

* configure complains about an illegal -q for grep.
It's used in a check for GNU ld. Could we use other options there or let grep be overridable to ggrep?

Since I am building on amd64, it also complained that libSDL is not amd64, so I use: --disable-sdl --disable-gfx-check

I can confirm the build failure due to stdbool.h. I therefore add: --extra-cflags=-std=gnu99

sparc-softmmu then compiles fine.

For i386-softmmu however,

* I get a flood of warnings from softfloat_native.h due to redefinitions of isunordered etc. (defined in Sun's math_c99.h), and

* the build of qemu fails to link due to undefined symbols __builtin_isinf and __builtin_isnan in libqemu.a(op_helper.o).

Looking at fpu/softfloat_native.h I see it makes assumptions about these macros that turn wrong when using the C99 headers. Any suggestion what to do here? It does not seem to depend on the GCC version since I am encountering this on 3.4.3, not 4.x.

If I prepend "0 && " to the #if line to avoid the redefinitions, I get compilation errors about __builtin_* functions:

gmake[1]: Entering directory `/export/home/andreas/QEMU/qemu/i386-softmmu'
Makefile:701: no file name for `-include'
gcc -I. -I.. -I/export/home/andreas/QEMU/qemu/target-i386 -I/export/home/andreas/QEMU/qemu -MMD -MT vl.o -MP -DNEED_CPU_H -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I/export/home/andreas/QEMU/qemu/tcg -I/export/home/andreas/QEMU/qemu/tcg/x86_64 -I/export/home/andreas/QEMU/qemu/fpu -DHAS_AUDIO -DHAS_AUDIO_CHOICE -I/export/home/andreas/QEMU/qemu/slirp -std=gnu99 -O2 -g -fno-strict-aliasing -Wall -Wundef -Wendif-labels -Wwrite-strings -m64 -c -o vl.o /export/home/andreas/QEMU/qemu/vl.c In file included from /export/home/andreas/QEMU/qemu/fpu/softfloat.h:440,
from /export/home/andreas/QEMU/qemu/target-i386/
cpu.h:47,

                 from ../qemu-common.h:62,
                 from /export/home/andreas/QEMU/qemu/hw/hw.h:5,
                 from /export/home/andreas/QEMU/qemu/vl.c:24:

/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `float32_le_quiet':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:217: error: syntax error before "__builtin_islessequal" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:218: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `float32_lt_quiet':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:221: error: syntax error before "__builtin_isless" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:222: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `float32_unordered':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:225: error: syntax error before "__builtin_isunordered" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:227: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `float64_le_quiet':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:307: error: syntax error before "__builtin_islessequal" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:308: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `float64_lt_quiet':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:311: error: syntax error before "__builtin_isless" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:313: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `float64_unordered':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:316: error: syntax error before "__builtin_isunordered" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:318: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `floatx80_le_quiet':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:394: error: syntax error before "__builtin_islessequal" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:395: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `floatx80_lt_quiet':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:398: error: syntax error before "__builtin_isless" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:400: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `floatx80_unordered':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:403: error: syntax error before "__builtin_isunordered" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:405: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/vl.c: At top level:
/export/home/andreas/QEMU/qemu/vl.c:205: warning: 'no_frame' defined but not used /export/home/andreas/QEMU/qemu/vl.c:5372: warning: 'qemu_find_bt_vlan' defined but not used gmake[1]: *** [vl.o] Error 1
gmake[1]: Leaving directory `/export/home/andreas/QEMU/qemu/i386-softmmu'
gmake: *** [subdir-i386-softmmu] Error 2

softfloat-native.h:217 does a simple "return islessequal(a, b);" - Sun's header has it defined as ((x) __builtin_islessequal(y)). This looks a little strange to me... Should we continue to override their macros, using #undef to avoid all the warnings, and define some additional ones for isinf and isnan, or is there a better solution?

The -include warning above appears to be related to dependency tracking only.

Andreas

#11 lore raw

Re: [Qemu-devel] QEMU on Solaris 10 (was: [PATCH 01/32] use anonymous memory for kqemu.)

Am 25.10.2008 um 12:17 schrieb Andreas Färber:

Quoted 11 lines

Am 24.10.2008 um 21:59 schrieb Ben Taylor:

Quoted 5 lines

the big problem I see is that the addition of c99 features borks a qemu compile on Solaris, specfically around stdbool.h. Turning on -std=c99 or -std=gnuc99 creates more problems because gcc-3.4.3 provided by solaris doesn't accept the anonymous unions that are prevalent around the new code, specifically nbd and vnc.

I just gave it a try on S10 5/08 amd64, using the gcc 3.4.3 from Sun and --disable-gcc-check

Quoted 8 lines

* configure complains about an illegal -q for grep.
It's used in a check for GNU ld. Could we use other options there or let grep be overridable to ggrep?

Since I am building on amd64, it also complained that libSDL is not amd64, so I use: --disable-sdl --disable-gfx-check

I can confirm the build failure due to stdbool.h. I therefore add: --extra-cflags=-std=gnu99

sparc-softmmu then compiles fine.

Small addition here: in hw/bt-hci.c in bt_submit_hci I spotted an implicit declaration of function `strndup'

This is at r5528 btw.

Quoted 62 lines

For i386-softmmu however,

* I get a flood of warnings from softfloat_native.h due to redefinitions of isunordered etc. (defined in Sun's math_c99.h), and

* the build of qemu fails to link due to undefined symbols __builtin_isinf and __builtin_isnan in libqemu.a(op_helper.o).

Looking at fpu/softfloat_native.h I see it makes assumptions about these macros that turn wrong when using the C99 headers. Any suggestion what to do here? It does not seem to depend on the GCC version since I am encountering this on 3.4.3, not 4.x.

If I prepend "0 && " to the #if line to avoid the redefinitions, I get compilation errors about __builtin_* functions:

gmake[1]: Entering directory `/export/home/andreas/QEMU/qemu/i386-softmmu'
Makefile:701: no file name for `-include'
gcc -I. -I.. -I/export/home/andreas/QEMU/qemu/target-i386 -I/export/home/andreas/QEMU/qemu -MMD -MT vl.o -MP -DNEED_CPU_H -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -I/export/home/andreas/QEMU/qemu/tcg -I/export/home/andreas/QEMU/qemu/tcg/x86_64 -I/export/home/andreas/QEMU/qemu/fpu -DHAS_AUDIO -DHAS_AUDIO_CHOICE -I/export/home/andreas/QEMU/qemu/slirp -std=gnu99 -O2 -g -fno-strict-aliasing -Wall -Wundef -Wendif-labels -Wwrite-strings -m64 -c -o vl.o /export/home/andreas/QEMU/qemu/vl.c In file included from /export/home/andreas/QEMU/qemu/fpu/softfloat.h:440,
from /export/home/andreas/QEMU/qemu/target-i386/
cpu.h:47,

                from ../qemu-common.h:62,
                from /export/home/andreas/QEMU/qemu/hw/hw.h:5,
                from /export/home/andreas/QEMU/qemu/vl.c:24:

/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `float32_le_quiet':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:217: error: syntax error before "__builtin_islessequal" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:218: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `float32_lt_quiet':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:221: error: syntax error before "__builtin_isless" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:222: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `float32_unordered':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:225: error: syntax error before "__builtin_isunordered" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:227: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `float64_le_quiet':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:307: error: syntax error before "__builtin_islessequal" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:308: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `float64_lt_quiet':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:311: error: syntax error before "__builtin_isless" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:313: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `float64_unordered':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:316: error: syntax error before "__builtin_isunordered" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:318: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `floatx80_le_quiet':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:394: error: syntax error before "__builtin_islessequal" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:395: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `floatx80_lt_quiet':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:398: error: syntax error before "__builtin_isless" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:400: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h: In function `floatx80_unordered':
/export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:403: error: syntax error before "__builtin_isunordered" /export/home/andreas/QEMU/qemu/fpu/softfloat-native.h:405: warning: no return statement in function returning non-void /export/home/andreas/QEMU/qemu/vl.c: At top level:
/export/home/andreas/QEMU/qemu/vl.c:205: warning: 'no_frame' defined but not used /export/home/andreas/QEMU/qemu/vl.c:5372: warning: 'qemu_find_bt_vlan' defined but not used gmake[1]: *** [vl.o] Error 1
gmake[1]: Leaving directory `/export/home/andreas/QEMU/qemu/i386-softmmu'
gmake: *** [subdir-i386-softmmu] Error 2

softfloat-native.h:217 does a simple "return islessequal(a, b);" - Sun's header has it defined as ((x) __builtin_islessequal(y)). This looks a little strange to me... Should we continue to override their macros, using #undef to avoid all the warnings, and define some additional ones for isinf and isnan, or is there a better solution?

The -include warning above appears to be related to dependency tracking only.

Andreas

#12 lore raw

Re: [Qemu-devel] QEMU on Solaris 10 (was: [PATCH 01/32] use anonymous memory for kqemu.)

Quoted 25 lines · Andreas Färber

Am 25.10.2008 um 12:17 schrieb Andreas Färber:

Quoted 4 lines

Am 24.10.2008 um 21:59 schrieb Ben Taylor:

Quoted 8 lines
Quoted 6 lines

the big problem I see is that the addition of c99 features borks a qemu compile on Solaris, specfically around stdbool.h. Turning on -std=c99 or -std=gnuc99 creates more problems because gcc-3.4.3 provided by solaris doesn't accept the anonymous unions that are prevalent around the new code, specifically nbd and vnc.

I just gave it a try on S10 5/08 amd64, using the gcc 3.4.3 from Sun and

--disable-gcc-check

Quoted 3 lines

* configure complains about an illegal -q for grep.
It's used in a check for GNU ld. Could we use other options there or let

grep be overridable to ggrep?

Quoted 2 lines

Since I am building on amd64, it also complained that libSDL is not amd64,

so I use: --disable-sdl --disable-gfx-check

Quoted 1 line
Quoted 8 lines
Quoted 1 line

I can confirm the build failure due to stdbool.h. I therefore add:

--extra-cflags=-std=gnu99

Quoted 3 lines

sparc-softmmu then compiles fine.

Small addition here: in hw/bt-hci.c in bt_submit_hci I spotted an implicit
declaration of function `strndup'

I get the same warning on OpenBSD, and there is also /src/qemu/hw/bt-hci.c:1818: warning: assignment makes pointer from integer without a cast

Maybe there should be a pstrdup function in cutils.c.

#13 lore raw

[Qemu-devel] Re: [PATCH 01/32] use anonymous memory for kqemu.

In reply to Anthony Liguori
Quoted 19 lines · Anthony Liguori
Quoted 18 lines · Jan Kiszka
Quoted 15 lines · Anthony Liguori

The idea behind this patch is that currently kqemu uses /dev/shm for memory allocations instead of anonymous memory (like the rest of QEMU). Instead of introducing YA hook, we can just switch kqemu to use
anonymous memory and eliminate the special case.

If I recall correctly, the reason for using /dev/shm was concern that get_user_pages() didn't do the right thing for anonymous memory and the use of /dev/shm was a hack around that. However, I'm not sure that was ever the case. Certainly, with any sufficiently modern kernel get_user_pages() does what one would expect. KVM uses get_user_pages() on anonymous memory in roughly the same way kqemu uses it now.

So I think it's safe to make the switch. Fabrice, what do you think?

Quoted 7 lines
Quoted 3 lines

This hack-around, was it purely Linux-motivated? Or did/do other OSes have similar issues?

/dev/shm doesn't exist on anything but Linux.

Regards,

I'm dropping this from the accel series until we reach a conclusion. This is not exactly needed for the health of the series, just for kqemu decoupling. This can proceed in parallel.

Quoted 7 lines

Anthony Liguori

Quoted 3 lines

Jan

#14 lore raw

PATCH 2/32 protect exec-all.h frm multiple inclusion

In reply to Glauber Costa
---
 exec-all.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
exec-all.h +3 -0
index 6609c9a..e3da98a 100644
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#ifndef _EXEC_ALL_H_
+#define _EXEC_ALL_H_
 /* allow to see translation results - the slowdown should be negligible, so we leave it */
 #define DEBUG_DISAS
 
@@ -385,3 +387,4 @@ static inline int kqemu_is_ok(CPUState *env)
 }
 
 #endif
+#endif
Signature · 1 line
1.5.5.1
#15 lore raw

[Qemu-devel] Re: [PATCH 02/32] protect exec-all.h frm multiple inclusion

Quoted 2 lines · Glauber Costa

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 23 lines
---
 exec-all.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
exec-all.h +3 -0
index 6609c9a..e3da98a 100644
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#ifndef _EXEC_ALL_H_
+#define _EXEC_ALL_H_
 /* allow to see translation results - the slowdown should be negligible, so we leave it */
 #define DEBUG_DISAS
 
@@ -385,3 +387,4 @@ static inline int kqemu_is_ok(CPUState *env)
 }
 
 #endif
+#endif
#16 lore raw

PATCH 3/32 change definition of FILE for linux

In reply to Glauber Costa

use _IO_FILE, as it seems to be the case.

---
 dyngen-exec.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
dyngen-exec.h +6 -0
index 9260b6f..826ff46 100644
@@ -27,6 +27,10 @@
 #define _FILEDEFED
 #endif
 
+#ifdef __linux__
+#define __FILE_defined
+#endif
+
 /* NOTE: standard headers should be used with special care at this
    point because host CPU registers are used as global variables. Some
    host headers do not allow that. */
@@ -84,6 +88,8 @@ typedef void * host_reg_t;
 
 #ifdef _BSD
 typedef struct __sFILE FILE;
+#elif defined(__linux__)
+typedef struct _IO_FILE FILE;
 #else
 typedef struct FILE FILE;
 #endif
Signature · 1 line
1.5.5.1
#17 lore raw

[Qemu-devel] Re: [PATCH 03/32] change definition of FILE for linux

Quoted 2 lines · Glauber Costa

use _IO_FILE, as it seems to be the case.

Why? What is this fixing?

It seems to work fine today and I don't see how this is related to the series.

Regards,

Anthony Liguori

Quoted 30 lines
---
 dyngen-exec.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
dyngen-exec.h +6 -0
index 9260b6f..826ff46 100644
@@ -27,6 +27,10 @@
 #define _FILEDEFED
 #endif
 
+#ifdef __linux__
+#define __FILE_defined
+#endif
+
 /* NOTE: standard headers should be used with special care at this
    point because host CPU registers are used as global variables. Some
    host headers do not allow that. */
@@ -84,6 +88,8 @@ typedef void * host_reg_t;
 
 #ifdef _BSD
 typedef struct __sFILE FILE;
+#elif defined(__linux__)
+typedef struct _IO_FILE FILE;
 #else
 typedef struct FILE FILE;
 #endif
#18 lore raw

[Qemu-devel] Re: [PATCH 03/32] change definition of FILE for linux

Quoted 8 lines · Anthony Liguori
Quoted 2 lines · Glauber Costa

use _IO_FILE, as it seems to be the case.

Why? What is this fixing?

It seems to work fine today and I don't see how this is related to the series.

It's not possible to include exec.h into kqemu.c without it, because it conflicts with virtually everything from stdio.h

The inclusion of exec.h is necessary for the cpu_exec patch, since we'll be using symbols defined in that header. OTOH, those symbols are mostly macros that cast env->something, and if really needed, I can use the env-> versions instead.

Quoted 36 lines

Regards,

Anthony Liguori

Quoted 30 lines
---
 dyngen-exec.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
dyngen-exec.h +6 -0
index 9260b6f..826ff46 100644
@@ -27,6 +27,10 @@
 #define _FILEDEFED
 #endif
 
+#ifdef __linux__
+#define __FILE_defined
+#endif
+
 /* NOTE: standard headers should be used with special care at this
    point because host CPU registers are used as global variables. Some
    host headers do not allow that. */
@@ -84,6 +88,8 @@ typedef void * host_reg_t;
 
 #ifdef _BSD
 typedef struct __sFILE FILE;
+#elif defined(__linux__)
+typedef struct _IO_FILE FILE;
 #else
 typedef struct FILE FILE;
 #endif
#19 lore raw

PATCH 4/32 move kqemu_cpu_exec to kqemu.c

In reply to Glauber Costa

Only pieces of code that are frame-safe can be moved. compute_all() is an example of a non-frame-safe calling. So it has to be done prior to calling kqemu_cpu_exec().

---
 cpu-exec.c |   33 +++++++++++++--------------------
 kqemu.c    |   18 +++++++++++++++++-
 2 files changed, 30 insertions(+), 21 deletions(-)
cpu-exec.c +13 -20
index 6d4dcdd..f06df26 100644
@@ -336,27 +336,20 @@ int cpu_exec(CPUState *env1)
                 env->exception_index = -1;
             }
 #ifdef USE_KQEMU
-            if (kqemu_is_ok(env) && env->interrupt_request == 0) {
-                int ret;
-                env->eflags = env->eflags | cc_table[CC_OP].compute_all() | (DF & DF_MASK);
-                ret = kqemu_cpu_exec(env);
-                /* put eflags in CPU temporary format */
-                CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-                DF = 1 - (2 * ((env->eflags >> 10) & 1));
-                CC_OP = CC_OP_EFLAGS;
-                env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-                if (ret == 1) {
-                    /* exception */
-                    longjmp(env->jmp_env, 1);
-                } else if (ret == 2) {
-                    /* softmmu execution needed */
+            env->eflags = env->eflags | cc_table[CC_OP].compute_all()  | (DF & DF_MASK);
+            ret = kqemu_cpu_exec(env);
+            env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
+            if (ret == 1) {
+                /* exception */
+                longjmp(env->jmp_env, 1);
+            } else if (ret == 2) {
+                /* softmmu execution needed */
+            } else {
+                if (env->interrupt_request != 0) {
+                    /* hardware interrupt will be executed just after */
                 } else {
-                    if (env->interrupt_request != 0) {
-                        /* hardware interrupt will be executed just after */
-                    } else {
-                        /* otherwise, we restart */
-                        longjmp(env->jmp_env, 1);
-                    }
+                    /* otherwise, we restart */
+                    longjmp(env->jmp_env, 1);
                 }
             }
 #endif
kqemu.c +17 -1
index 4783aa2..39938e0 100644
@@ -30,6 +30,7 @@
 #ifdef HOST_SOLARIS
 #include <sys/ioccom.h>
 #endif
+#include "exec.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
@@ -689,7 +690,7 @@ static inline void kqemu_save_seg(SegmentCache *sc,
     sc->base = ksc->base;
 }
 
-int kqemu_cpu_exec(CPUState *env)
+int kqemu_do_cpu_exec(CPUState *env)
 {
     struct kqemu_cpu_state kcpu_state, *kenv = &kcpu_state;
     int ret, cpl, i;
@@ -939,6 +940,21 @@ int kqemu_cpu_exec(CPUState *env)
     return 0;
 }
 
+int kqemu_cpu_exec(CPUState *env)
+{
+
+    int ret = 2;
+    if (kqemu_is_ok(env) && env->interrupt_request == 0) {
+        ret = kqemu_do_cpu_exec(env);
+        /* put eflags in CPU temporary format */
+        CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
+        DF = 1 - (2 * ((env->eflags >> 10) & 1));
+        CC_OP = CC_OP_EFLAGS;
+    }
+    return ret;
+}
+
+
 void kqemu_cpu_interrupt(CPUState *env)
 {
 #if defined(_WIN32)
Signature · 1 line
1.5.5.1
#20 lore raw

[Qemu-devel] Re: [PATCH 04/32] move kqemu_cpu_exec to kqemu.c

Quoted 24 lines · Glauber Costa

Only pieces of code that are frame-safe can be moved. compute_all() is an example of a non-frame-safe calling. So it has to be done prior to calling kqemu_cpu_exec().

---
 cpu-exec.c |   33 +++++++++++++--------------------
 kqemu.c    |   18 +++++++++++++++++-
 2 files changed, 30 insertions(+), 21 deletions(-)
cpu-exec.c +0 -6
index 6d4dcdd..f06df26 100644
@@ -336,27 +336,20 @@ int cpu_exec(CPUState *env1)
                 env->exception_index = -1;
             }
 #ifdef USE_KQEMU
-            if (kqemu_is_ok(env) && env->interrupt_request == 0) {
-                int ret;
-                env->eflags = env->eflags | cc_table[CC_OP].compute_all() | (DF & DF_MASK);
-                ret = kqemu_cpu_exec(env);
-                /* put eflags in CPU temporary format */
-                CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);

cpu-exec.c int cpu_exec(CPUState *env1) · line 340

Quoted 10 lines
cpu-exec.c +1 -8
-                DF = 1 - (2 * ((env->eflags >> 10) & 1));
-                CC_OP = CC_OP_EFLAGS;
-                env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-                if (ret == 1) {
-                    /* exception */
-                    longjmp(env->jmp_env, 1);
-                } else if (ret == 2) {
-                    /* softmmu execution needed */
+            env->eflags = env->eflags | cc_table[CC_OP].compute_all()  | (DF & DF_MASK);
 

Can't do this unconditionally since you're now recomputing all condition flags even when kqemu is not in use. So unfortunately I'm not sure the code can be cleaned up much more if compute_all() must stay in cpu_exec.

Regards,

Anthony Liguori

Quoted 66 lines
cpu-exec.c +12 -6
+            ret = kqemu_cpu_exec(env);
+            env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
+            if (ret == 1) {
+                /* exception */
+                longjmp(env->jmp_env, 1);
+            } else if (ret == 2) {
+                /* softmmu execution needed */
+            } else {
+                if (env->interrupt_request != 0) {
+                    /* hardware interrupt will be executed just after */
                 } else {
-                    if (env->interrupt_request != 0) {
-                        /* hardware interrupt will be executed just after */
-                    } else {
-                        /* otherwise, we restart */
-                        longjmp(env->jmp_env, 1);
-                    }
+                    /* otherwise, we restart */
+                    longjmp(env->jmp_env, 1);
                 }
             }

#endif

kqemu.c +17 -1
index 4783aa2..39938e0 100644
@@ -30,6 +30,7 @@
 #ifdef HOST_SOLARIS
 #include <sys/ioccom.h>
 #endif
+#include "exec.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
@@ -689,7 +690,7 @@ static inline void kqemu_save_seg(SegmentCache *sc,
     sc->base = ksc->base;
 }
 
-int kqemu_cpu_exec(CPUState *env)
+int kqemu_do_cpu_exec(CPUState *env)
 {
     struct kqemu_cpu_state kcpu_state, *kenv = &kcpu_state;
     int ret, cpl, i;
@@ -939,6 +940,21 @@ int kqemu_cpu_exec(CPUState *env)
     return 0;
 }
 
+int kqemu_cpu_exec(CPUState *env)
+{
+
+    int ret = 2;
+    if (kqemu_is_ok(env) && env->interrupt_request == 0) {
+        ret = kqemu_do_cpu_exec(env);
+        /* put eflags in CPU temporary format */
+        CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
+        DF = 1 - (2 * ((env->eflags >> 10) & 1));
+        CC_OP = CC_OP_EFLAGS;
+    }
+    return ret;
+}
+
+
 void kqemu_cpu_interrupt(CPUState *env)
 {
 #if defined(_WIN32)
#21 lore raw

[Qemu-devel] Re: [PATCH 04/32] move kqemu_cpu_exec to kqemu.c

Quoted 40 lines · Anthony Liguori
Quoted 24 lines · Glauber Costa

Only pieces of code that are frame-safe can be moved. compute_all() is an example of a non-frame-safe calling. So it has to be done prior to calling kqemu_cpu_exec().

---
 cpu-exec.c |   33 +++++++++++++--------------------
 kqemu.c    |   18 +++++++++++++++++-
 2 files changed, 30 insertions(+), 21 deletions(-)
cpu-exec.c +0 -6
index 6d4dcdd..f06df26 100644
@@ -336,27 +336,20 @@ int cpu_exec(CPUState *env1)
                 env->exception_index = -1;
             }
 #ifdef USE_KQEMU
-            if (kqemu_is_ok(env) && env->interrupt_request == 0) {
-                int ret;
-                env->eflags = env->eflags | cc_table[CC_OP].compute_all() | (DF & DF_MASK);
-                ret = kqemu_cpu_exec(env);
-                /* put eflags in CPU temporary format */
-                CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);

cpu-exec.c int cpu_exec(CPUState *env1) · line 340

Quoted 10 lines
cpu-exec.c +1 -8
-                DF = 1 - (2 * ((env->eflags >> 10) & 1));
-                CC_OP = CC_OP_EFLAGS;
-                env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-                if (ret == 1) {
-                    /* exception */
-                    longjmp(env->jmp_env, 1);
-                } else if (ret == 2) {
-                    /* softmmu execution needed */
+            env->eflags = env->eflags | cc_table[CC_OP].compute_all()  | (DF & DF_MASK);
 

Can't do this unconditionally since you're now recomputing all condition flags even when kqemu is not in use. So unfortunately I'm not sure the code can be cleaned up much more if compute_all() must stay in cpu_exec.

Quoted 1 line

Regards,

We can add an auxiliary function into the accel structure in which the accelerator indicates whether or not it needs the condition flags to be recomputed.

But, in general, I'm fine with not touching it, since kvm io thread's implementation does not rely on this code path. Don't know about xen or any other interested parties, tough.

Quoted 70 lines

Anthony Liguori

Quoted 66 lines
cpu-exec.c +12 -6
+            ret = kqemu_cpu_exec(env);
+            env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
+            if (ret == 1) {
+                /* exception */
+                longjmp(env->jmp_env, 1);
+            } else if (ret == 2) {
+                /* softmmu execution needed */
+            } else {
+                if (env->interrupt_request != 0) {
+                    /* hardware interrupt will be executed just after */
                 } else {
-                    if (env->interrupt_request != 0) {
-                        /* hardware interrupt will be executed just after */
-                    } else {
-                        /* otherwise, we restart */
-                        longjmp(env->jmp_env, 1);
-                    }
+                    /* otherwise, we restart */
+                    longjmp(env->jmp_env, 1);
                 }
             }

#endif

kqemu.c +17 -1
index 4783aa2..39938e0 100644
@@ -30,6 +30,7 @@
 #ifdef HOST_SOLARIS
 #include <sys/ioccom.h>
 #endif
+#include "exec.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
@@ -689,7 +690,7 @@ static inline void kqemu_save_seg(SegmentCache *sc,
     sc->base = ksc->base;
 }
 
-int kqemu_cpu_exec(CPUState *env)
+int kqemu_do_cpu_exec(CPUState *env)
 {
     struct kqemu_cpu_state kcpu_state, *kenv = &kcpu_state;
     int ret, cpl, i;
@@ -939,6 +940,21 @@ int kqemu_cpu_exec(CPUState *env)
     return 0;
 }
 
+int kqemu_cpu_exec(CPUState *env)
+{
+
+    int ret = 2;
+    if (kqemu_is_ok(env) && env->interrupt_request == 0) {
+        ret = kqemu_do_cpu_exec(env);
+        /* put eflags in CPU temporary format */
+        CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
+        DF = 1 - (2 * ((env->eflags >> 10) & 1));
+        CC_OP = CC_OP_EFLAGS;
+    }
+    return ret;
+}
+
+
 void kqemu_cpu_interrupt(CPUState *env)
 {
 #if defined(_WIN32)
#22 lore raw

PATCH 5/32 use more meaningful values for kqemu_cpu_exec

In reply to Glauber Costa

define constants that actually mean something instead of 1, 2, etc

---
 cpu-exec.c |    4 ++--
 exec-all.h |    4 ++++
 kqemu.c    |   12 ++++++------
 3 files changed, 12 insertions(+), 8 deletions(-)
cpu-exec.c +2 -2
index f06df26..88b7d6f 100644
@@ -339,10 +339,10 @@ int cpu_exec(CPUState *env1)
             env->eflags = env->eflags | cc_table[CC_OP].compute_all()  | (DF & DF_MASK);
             ret = kqemu_cpu_exec(env);
             env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-            if (ret == 1) {
+            if (ret == EXEC_EXIT_INTR) {
                 /* exception */
                 longjmp(env->jmp_env, 1);
-            } else if (ret == 2) {
+            } else if (ret == EXEC_EXIT_SOFTMMU) {
                 /* softmmu execution needed */
             } else {
                 if (env->interrupt_request != 0) {
exec-all.h +4 -0
index e3da98a..c10248b 100644
@@ -356,6 +356,10 @@ static inline int can_do_io(CPUState *env)
 }
 #endif
 
+#define EXEC_EXIT_DONE 0
+#define EXEC_EXIT_INTR 1
+#define EXEC_EXIT_SOFTMMU 2
+
 #ifdef USE_KQEMU
 #define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))
 
kqemu.c +6 -6
index 39938e0..d2bfd05 100644
@@ -892,7 +892,7 @@ int kqemu_do_cpu_exec(CPUState *env)
             cpu_dump_state(env, logfile, fprintf, 0);
         }
 #endif
-        return 1;
+        return EXEC_EXIT_INTR;
     } else if ((ret & 0xff00) == KQEMU_RET_EXCEPTION) {
         env->exception_index = ret & 0xff;
         env->error_code = kenv->error_code;
@@ -908,7 +908,7 @@ int kqemu_do_cpu_exec(CPUState *env)
             cpu_dump_state(env, logfile, fprintf, 0);
         }
 #endif
-        return 1;
+        return EXEC_EXIT_INTR;
     } else if (ret == KQEMU_RET_INTR) {
 #ifdef CONFIG_PROFILER
         kqemu_ret_intr_count++;
@@ -918,7 +918,7 @@ int kqemu_do_cpu_exec(CPUState *env)
             cpu_dump_state(env, logfile, fprintf, 0);
         }
 #endif
-        return 0;
+        return EXEC_EXIT_DONE;
     } else if (ret == KQEMU_RET_SOFTMMU) {
 #ifdef CONFIG_PROFILER
         {
@@ -931,19 +931,19 @@ int kqemu_do_cpu_exec(CPUState *env)
             cpu_dump_state(env, logfile, fprintf, 0);
         }
 #endif
-        return 2;
+        return EXEC_EXIT_SOFTMMU;
     } else {
         cpu_dump_state(env, stderr, fprintf, 0);
         fprintf(stderr, "Unsupported return value: 0x%x\n", ret);
         exit(1);
     }
-    return 0;
+    return EXEC_EXIT_DONE;
 }
 
 int kqemu_cpu_exec(CPUState *env)
 {
 
-    int ret = 2;
+    int ret = EXEC_EXIT_SOFTMMU;
     if (kqemu_is_ok(env) && env->interrupt_request == 0) {
         ret = kqemu_do_cpu_exec(env);
         /* put eflags in CPU temporary format */
Signature · 1 line
1.5.5.1
#23 lore raw

[Qemu-devel] Re: [PATCH 05/32] use more meaningful values for kqemu_cpu_exec

Quoted 31 lines · Glauber Costa

define constants that actually mean something instead of 1, 2, etc

---
 cpu-exec.c |    4 ++--
 exec-all.h |    4 ++++
 kqemu.c    |   12 ++++++------
 3 files changed, 12 insertions(+), 8 deletions(-)
cpu-exec.c +2 -2
index f06df26..88b7d6f 100644
@@ -339,10 +339,10 @@ int cpu_exec(CPUState *env1)
             env->eflags = env->eflags | cc_table[CC_OP].compute_all()  | (DF & DF_MASK);
             ret = kqemu_cpu_exec(env);
             env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-            if (ret == 1) {
+            if (ret == EXEC_EXIT_INTR) {
                 /* exception */
                 longjmp(env->jmp_env, 1);
-            } else if (ret == 2) {
+            } else if (ret == EXEC_EXIT_SOFTMMU) {
                 /* softmmu execution needed */
             } else {
                 if (env->interrupt_request != 0) {
exec-all.h +0 -0
index e3da98a..c10248b 100644

exec-all.h static inline int can_do_io(CPUState *env) · line 363

Quoted 8 lines
exec-all.h +4 -0
@@ -356,6 +356,10 @@ static inline int can_do_io(CPUState *env)
 }
 #endif
 
+#define EXEC_EXIT_DONE 0
+#define EXEC_EXIT_INTR 1
+#define EXEC_EXIT_SOFTMMU 2
+
 

How about ACCEL_EXIT_? These codes are accelerator specific after all.

Regards,

Anthony Liguori

#24 lore raw

[Qemu-devel] Re: [PATCH 05/32] use more meaningful values for kqemu_cpu_exec

Quoted 35 lines · Anthony Liguori
Quoted 34 lines · Glauber Costa

define constants that actually mean something instead of 1, 2, etc

---
 cpu-exec.c |    4 ++--
 exec-all.h |    4 ++++
 kqemu.c    |   12 ++++++------
 3 files changed, 12 insertions(+), 8 deletions(-)
cpu-exec.c +2 -2
index f06df26..88b7d6f 100644
@@ -339,10 +339,10 @@ int cpu_exec(CPUState *env1)
             env->eflags = env->eflags | cc_table[CC_OP].compute_all()  | (DF & DF_MASK);
             ret = kqemu_cpu_exec(env);
             env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-            if (ret == 1) {
+            if (ret == EXEC_EXIT_INTR) {
                 /* exception */
                 longjmp(env->jmp_env, 1);
-            } else if (ret == 2) {
+            } else if (ret == EXEC_EXIT_SOFTMMU) {
                 /* softmmu execution needed */
             } else {
                 if (env->interrupt_request != 0) {
exec-all.h +0 -0
index e3da98a..c10248b 100644
@@ -356,6 +356,10 @@ static inline int can_do_io(CPUState *env)
 }
 #endif
 
Quoted 7 lines

exec-all.h static inline int can_do_io(CPUState *env) · line 365

Quoted 5 lines
exec-all.h +4 -0
+#define EXEC_EXIT_DONE 0
+#define EXEC_EXIT_INTR 1
+#define EXEC_EXIT_SOFTMMU 2
+
 

How about ACCEL_EXIT_? These codes are accelerator specific after all.

I believe ACCEL_EXIT is confusing. ACCEL_EXEC_EXIT would be better, since it makes it clear that it is used in exec context. However, if we're droping the cpu_exec patch, we can drop this one too.

Quoted 5 lines

Regards,

Anthony Liguori

#25 lore raw

PATCH 6/32 split kqemu_init into two

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

we separate kqemu_init() into a part that depends on env, and other that does not. The later can be initialized earlier

---
 exec-all.h           |    1 -
 exec.c               |    5 ++++-
 kqemu.c              |   10 +++++++---
 target-i386/helper.c |    2 +-
 4 files changed, 12 insertions(+), 6 deletions(-)
exec-all.h +0 -1
index c10248b..9ea9b4e 100644
@@ -365,7 +365,6 @@ static inline int can_do_io(CPUState *env)
 
 #define MSR_QPI_COMMBASE 0xfabe0010
 
-int kqemu_init(CPUState *env);
 int kqemu_cpu_exec(CPUState *env);
 void kqemu_flush_page(CPUState *env, target_ulong addr);
 void kqemu_flush(CPUState *env, int global);
exec.c +4 -1
index f1fcec8..1cad0be 100644
@@ -495,6 +495,9 @@ void cpu_exec_init_all(unsigned long tb_size)
 #if !defined(CONFIG_USER_ONLY)
     io_mem_init();
 #endif
+#ifdef USE_KQEMU
+    kqemu_start();
+#endif
 }
 
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
@@ -2207,7 +2210,7 @@ void cpu_register_physical_memory(target_phys_addr_t start_addr,
 #ifdef USE_KQEMU
     /* XXX: should not depend on cpu context */
     env = first_cpu;
-    if (env->kqemu_enabled) {
+    if (env && env->kqemu_enabled) {
         kqemu_set_phys_mem(start_addr, size, phys_offset);
     }
 #endif
kqemu.c +7 -3
index d2bfd05..11f8c8a 100644
@@ -151,7 +151,7 @@ static void kqemu_update_cpuid(CPUState *env)
        accelerated code */
 }
 
-int kqemu_init(CPUState *env)
+int kqemu_start(void)
 {
     struct kqemu_init kinit;
     int ret, version;
@@ -231,8 +231,6 @@ int kqemu_init(CPUState *env)
         kqemu_fd = KQEMU_INVALID_FD;
         return -1;
     }
-    kqemu_update_cpuid(env);
-    env->kqemu_enabled = kqemu_allowed;
     nb_pages_to_flush = 0;
     nb_ram_pages_to_update = 0;
 
@@ -240,6 +238,12 @@ int kqemu_init(CPUState *env)
     return 0;
 }
 
+void kqemu_init_env(CPUState *env)
+{
+    kqemu_update_cpuid(env);
+    env->kqemu_enabled = kqemu_allowed;
+}
+
 void kqemu_flush_page(CPUState *env, target_ulong addr)
 {
 #if defined(DEBUG)
target-i386/helper.c +1 -1
index c2e1a88..b36e391 100644
@@ -113,7 +113,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
     }
     cpu_reset(env);
 #ifdef USE_KQEMU
-    kqemu_init(env);
+    kqemu_init_env(env);
 #endif
     return env;
 }
Signature · 1 line
1.5.5.1
#26 lore raw

[Qemu-devel] Re: [PATCH 06/32] split kqemu_init into two

Quoted 5 lines · Glauber Costa

From: Glauber Costa <[email protected]>

we separate kqemu_init() into a part that depends on env, and other that does not. The later can be initialized earlier

This patch seems harmless but I can't reasonably infer why this change is necessary. What's the advantage of splitting the initialization into two parts?

Regards,

Anthony Liguori

#27 lore raw

[Qemu-devel] Re: [PATCH 06/32] split kqemu_init into two

Quoted 11 lines · Anthony Liguori
Quoted 5 lines · Glauber Costa

From: Glauber Costa <[email protected]>

we separate kqemu_init() into a part that depends on env, and other that does not. The later can be initialized earlier

This patch seems harmless but I can't reasonably infer why this change is necessary. What's the advantage of splitting the initialization into two parts?

the previous version receives a CPUState parameter. If we do that, we never give the accelerator the chance to care for its own CPUState. So that's the reason behind the split: First, we kickstart the accelerator, which can suceed / fail. Later on, we overwrite the cpu_env initialization to give the accel a chance.

Quoted 4 lines

Regards,

Anthony Liguori

#28 lore raw

PATCH 7/32 introduce QEMUAccel and fill it with interrupt specific driver

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

This patch introduces QEMUAccel, a placeholder for function pointers that aims at helping qemu to abstract accelerators such as kqemu and kvm (actually, the 'accelerator' name was proposed by avi kivity, since he loves referring to kvm that way).

To begin with, the accelerator is given the opportunity to register a cpu_interrupt function, to be called after the raw cpu_interrupt.
This has the side effect of, for the kqemu accelerator, calling kqemu_cpu_interrupt everytime, which didn't use to happen. But looking at the code, this seems safe to me.

This patch applies on raw qemu.

---
 Makefile.target |    2 +-
 accel.c         |   17 +++++++++++++++++
 accel.h         |   20 ++++++++++++++++++++
 exec-all.h      |    1 -
 exec.c          |    3 +++
 kqemu.c         |   11 ++++++++++-
 vl.c            |   17 +++++------------
 7 files changed, 56 insertions(+), 15 deletions(-)
 create mode 100644 accel.c
 create mode 100644 accel.h
Makefile.target +1 -1
index e2edf9d..623ecd8 100644
@@ -188,7 +188,7 @@ all: $(PROGS)
 #########################################################
 # cpu emulator library
 LIBOBJS=exec.o kqemu.o translate-all.o cpu-exec.o\
-        translate.o host-utils.o
+        translate.o host-utils.o accel.o
 ifdef CONFIG_DYNGEN_OP
 exec.o: dyngen-opc.h
 LIBOBJS+=op.o
accel.c new file +17 -0
new file mode 100644
index 0000000..d30460d
@@ -0,0 +1,17 @@
+#include "hw/hw.h"
+#include "accel.h"
+
+QEMUAccel *current_accel;
+
+int _accel_nop(void)
+{
+    return 0;
+}
+
+#define accel_nop ((void *)_accel_nop)
+
+/* Accelerator wrapper for the no-accel (raw qemu) case */
+QEMUAccel noaccel = {
+    .cpu_interrupt = accel_nop,
+};
+
accel.h new file +20 -0
new file mode 100644
index 0000000..8e5ddc6
@@ -0,0 +1,20 @@
+#ifndef _ACCEL_H_
+#define _ACCEL_H_
+
+typedef struct QEMUAccel {
+    void (*cpu_interrupt)(CPUState *env);
+} QEMUAccel;
+
+extern QEMUAccel *current_accel;
+extern QEMUAccel noaccel;
+
+static inline void register_qemu_accel(QEMUAccel *accel)
+{
+    current_accel = accel;
+}
+
+static inline void accel_cpu_interrupt(CPUState *env)
+{
+    current_accel->cpu_interrupt(env);
+}
+#endif
exec-all.h +0 -1
index 9ea9b4e..0a84f58 100644
@@ -372,7 +372,6 @@ void kqemu_set_notdirty(CPUState *env, ram_addr_t ram_addr);
 void kqemu_modify_page(CPUState *env, ram_addr_t ram_addr);
 void kqemu_set_phys_mem(uint64_t start_addr, ram_addr_t size, 
                         ram_addr_t phys_offset);
-void kqemu_cpu_interrupt(CPUState *env);
 void kqemu_record_dump(void);
 
 extern uint32_t kqemu_comm_base;
exec.c +3 -0
index 1cad0be..21253cc 100644
@@ -43,6 +43,8 @@
 #include <qemu.h>
 #endif
 
+#include "accel.h"
+
 //#define DEBUG_TB_INVALIDATE
 //#define DEBUG_FLUSH
 //#define DEBUG_TLB
@@ -1430,6 +1432,7 @@ void cpu_single_step(CPUState *env, int enabled)
         tb_flush(env);
     }
 #endif
+    accel_cpu_interrupt(env);
 }
 
 /* enable or disable low levels log */
kqemu.c +10 -1
index 11f8c8a..dc989a3 100644
@@ -51,6 +51,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include "kqemu.h"
+#include "accel.h"
 
 #ifdef _WIN32
 #define KQEMU_DEVICE "\\\\.\\kqemu"
@@ -151,6 +152,8 @@ static void kqemu_update_cpuid(CPUState *env)
        accelerated code */
 }
 
+QEMUAccel kqemu_accel;
+
 int kqemu_start(void)
 {
     struct kqemu_init kinit;
@@ -233,6 +236,7 @@ int kqemu_start(void)
     }
     nb_pages_to_flush = 0;
     nb_ram_pages_to_update = 0;
+    register_qemu_accel(&kqemu_accel);
 
     qpi_init();
     return 0;
@@ -959,7 +963,7 @@ int kqemu_cpu_exec(CPUState *env)
 }
 
 
-void kqemu_cpu_interrupt(CPUState *env)
+static void kqemu_cpu_interrupt(CPUState *env)
 {
 #if defined(_WIN32)
     /* cancelling the I/O request causes KQEMU to finish executing the
@@ -1042,4 +1046,9 @@ static void qpi_init(void)
     cpu_register_physical_memory(kqemu_comm_base & ~0xfff, 
                                  0x1000, qpi_io_memory);
 }
+
+QEMUAccel kqemu_accel = {
+    .cpu_interrupt = kqemu_cpu_interrupt,
+};
+
 #endif
vl.c +5 -12
index c0e43ac..adf5b25 100644
@@ -149,6 +149,8 @@
 #define SMBD_COMMAND "/usr/sbin/smbd"
 #endif
 
+#include "accel.h"
+
 //#define DEBUG_UNUSED_IOPORT
 //#define DEBUG_IOPORT
 //#define DEBUG_NET
@@ -1317,11 +1319,6 @@ static void host_alarm_handler(int host_signum)
         if (env) {
             /* stop the currently executing cpu because a timer occured */
             cpu_interrupt(env, CPU_INTERRUPT_EXIT);
-#ifdef USE_KQEMU
-            if (env->kqemu_enabled) {
-                kqemu_cpu_interrupt(env);
-            }
-#endif
         }
         event_pending = 1;
     }
@@ -7560,14 +7557,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
 void qemu_service_io(void)
 {
     CPUState *env = cpu_single_env;
-    if (env) {
+    if (env)
         cpu_interrupt(env, CPU_INTERRUPT_EXIT);
-#ifdef USE_KQEMU
-        if (env->kqemu_enabled) {
-            kqemu_cpu_interrupt(env);
-        }
-#endif
-    }
 }
 
 /***********************************************************/
@@ -8824,6 +8815,8 @@ int main(int argc, char **argv)
     }
 #endif
 
+    register_qemu_accel(&noaccel);
+
     register_machines();
     machine = first_machine;
     cpu_model = NULL;
Signature · 1 line
1.5.5.1
#29 lore raw

[Qemu-devel] Re: [PATCH 07/32] introduce QEMUAccel and fill it with interrupt specific driver

Quoted 7 lines · Glauber Costa

From: Glauber Costa <[email protected]>

This patch introduces QEMUAccel, a placeholder for function pointers that aims at helping qemu to abstract accelerators such as kqemu and kvm (actually, the 'accelerator' name was proposed by avi kivity, since he loves referring to kvm that way).

Quoted 8 lines

To begin with, the accelerator is given the opportunity to register a cpu_interrupt function, to be called after the raw cpu_interrupt.
This has the side effect of, for the kqemu accelerator, calling kqemu_cpu_interrupt everytime, which didn't use to happen. But looking at the code, this seems safe to me.

This patch applies on raw qemu.

See my previous bit of feedback. cpu_interrupt place to be hooking. It really ought to be an io_window or cpu_loop_exit hook or something like that.

Regards,

Anthony Liguori

#30 lore raw

PATCH 8/32 init env made accel driver

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

Yet another accel field: init_env

---
 accel.c              |    1 +
 accel.h              |    7 +++++++
 kqemu.c              |    3 ++-
 target-i386/helper.c |    6 +++---
 4 files changed, 13 insertions(+), 4 deletions(-)
accel.c +1 -0
index d30460d..3a17dc5 100644
@@ -13,5 +13,6 @@ int _accel_nop(void)
 /* Accelerator wrapper for the no-accel (raw qemu) case */
 QEMUAccel noaccel = {
     .cpu_interrupt = accel_nop,
+    .init_env = accel_nop,
 };
 
accel.h +7 -0
index 8e5ddc6..0d916dc 100644
@@ -3,6 +3,7 @@
 
 typedef struct QEMUAccel {
     void (*cpu_interrupt)(CPUState *env);
+    void (*init_env)(CPUState *env);
 } QEMUAccel;
 
 extern QEMUAccel *current_accel;
@@ -17,4 +18,10 @@ static inline void accel_cpu_interrupt(CPUState *env)
 {
     current_accel->cpu_interrupt(env);
 }
+
+static inline void accel_init_env(CPUState *env)
+{
+    current_accel->init_env(env);
+}
+
 #endif
kqemu.c +2 -1
index dc989a3..8c228f4 100644
@@ -242,7 +242,7 @@ int kqemu_start(void)
     return 0;
 }
 
-void kqemu_init_env(CPUState *env)
+static void kqemu_init_env(CPUState *env)
 {
     kqemu_update_cpuid(env);
     env->kqemu_enabled = kqemu_allowed;
@@ -1049,6 +1049,7 @@ static void qpi_init(void)
 
 QEMUAccel kqemu_accel = {
     .cpu_interrupt = kqemu_cpu_interrupt,
+    .init_env = kqemu_init_env,
 };
 
 #endif
target-i386/helper.c +3 -3
index b36e391..b981b92 100644
@@ -30,6 +30,8 @@
 #include "svm.h"
 #include "qemu-common.h"
 
+#include "accel.h"
+
 //#define DEBUG_MMU
 
 static int cpu_x86_register (CPUX86State *env, const char *cpu_model);
@@ -112,9 +114,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
         return NULL;
     }
     cpu_reset(env);
-#ifdef USE_KQEMU
-    kqemu_init_env(env);
-#endif
+    accel_init_env(env);
     return env;
 }
 
Signature · 1 line
1.5.5.1
#31 lore raw

PATCH 9/32 wrap cache flushing functions into accel drivers

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

Yet another accel field: cache flushing functions

---
 accel.c    |    2 ++
 accel.h    |   11 +++++++++++
 exec-all.h |    2 --
 exec.c     |   13 +++----------
 kqemu.c    |    6 ++++--
 5 files changed, 20 insertions(+), 14 deletions(-)
accel.c +2 -0
index 3a17dc5..6776244 100644
@@ -14,5 +14,7 @@ int _accel_nop(void)
 QEMUAccel noaccel = {
     .cpu_interrupt = accel_nop,
     .init_env = accel_nop,
+    .flush_cache = accel_nop,
+    .flush_page = accel_nop,
 };
 
accel.h +11 -0
index 0d916dc..935cfef 100644
@@ -4,6 +4,8 @@
 typedef struct QEMUAccel {
     void (*cpu_interrupt)(CPUState *env);
     void (*init_env)(CPUState *env);
+    void (*flush_cache)(CPUState *env, int global);
+    void (*flush_page)(CPUState *env, target_ulong addr);
 } QEMUAccel;
 
 extern QEMUAccel *current_accel;
@@ -24,4 +26,13 @@ static inline void accel_init_env(CPUState *env)
     current_accel->init_env(env);
 }
 
+static inline void accel_flush_cache(CPUState *env, int global)
+{
+    current_accel->flush_cache(env, global);
+}
+
+static inline void accel_flush_page(CPUState *env, target_ulong addr)
+{
+    current_accel->flush_page(env, addr);
+}
 #endif
exec-all.h +0 -2
index 0a84f58..2098fe8 100644
@@ -366,8 +366,6 @@ static inline int can_do_io(CPUState *env)
 #define MSR_QPI_COMMBASE 0xfabe0010
 
 int kqemu_cpu_exec(CPUState *env);
-void kqemu_flush_page(CPUState *env, target_ulong addr);
-void kqemu_flush(CPUState *env, int global);
 void kqemu_set_notdirty(CPUState *env, ram_addr_t ram_addr);
 void kqemu_modify_page(CPUState *env, ram_addr_t ram_addr);
 void kqemu_set_phys_mem(uint64_t start_addr, ram_addr_t size, 
exec.c +3 -10
index 21253cc..4f7aa67 100644
@@ -1684,11 +1684,8 @@ void tlb_flush(CPUState *env, int flush_global)
 
     memset (env->tb_jmp_cache, 0, TB_JMP_CACHE_SIZE * sizeof (void *));
 
-#ifdef USE_KQEMU
-    if (env->kqemu_enabled) {
-        kqemu_flush(env, flush_global);
-    }
-#endif
+    accel_flush_cache(env, flush_global);
+
     tlb_flush_count++;
 }
 
@@ -1730,11 +1727,7 @@ void tlb_flush_page(CPUState *env, target_ulong addr)
 
     tlb_flush_jmp_cache(env, addr);
 
-#ifdef USE_KQEMU
-    if (env->kqemu_enabled) {
-        kqemu_flush_page(env, addr);
-    }
-#endif
+    accel_flush_page(env, addr);
 }
 
 /* update the TLBs so that writes to code in the virtual page 'addr'
kqemu.c +4 -2
index 8c228f4..3f2433a 100644
@@ -248,7 +248,7 @@ static void kqemu_init_env(CPUState *env)
     env->kqemu_enabled = kqemu_allowed;
 }
 
-void kqemu_flush_page(CPUState *env, target_ulong addr)
+static void kqemu_flush_page(CPUState *env, target_ulong addr)
 {
 #if defined(DEBUG)
     if (loglevel & CPU_LOG_INT) {
@@ -261,7 +261,7 @@ void kqemu_flush_page(CPUState *env, target_ulong addr)
         pages_to_flush[nb_pages_to_flush++] = addr;
 }
 
-void kqemu_flush(CPUState *env, int global)
+static void kqemu_flush(CPUState *env, int global)
 {
 #ifdef DEBUG
     if (loglevel & CPU_LOG_INT) {
@@ -1050,6 +1050,8 @@ static void qpi_init(void)
 QEMUAccel kqemu_accel = {
     .cpu_interrupt = kqemu_cpu_interrupt,
     .init_env = kqemu_init_env,
+    .flush_cache = kqemu_flush,
+    .flush_page = kqemu_flush_page,
 };
 
 #endif
Signature · 1 line
1.5.5.1
#32 lore raw

PATCH 10/32 turn info kqemu into generic info accelerator

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

Yet another accel field: info.

Quoted 1 line

From this point on, "info kqemu" is no more. "info accelerator" should

be used instead.

---
 accel.c   |    6 ++++++
 accel.h   |    8 ++++++++
 kqemu.c   |   26 ++++++++++++++++++++++++++
 monitor.c |   35 ++++++++++++-----------------------
 4 files changed, 52 insertions(+), 23 deletions(-)
accel.c +6 -0
index 6776244..cb615d7 100644
@@ -8,6 +8,11 @@ int _accel_nop(void)
     return 0;
 }
 
+int noaccel_info(CPUState *env, char *buf)
+{
+    return snprintf(buf, MAX_INFO_BUF, "no accelerator present.\n");
+}
+
 #define accel_nop ((void *)_accel_nop)
 
 /* Accelerator wrapper for the no-accel (raw qemu) case */
@@ -16,5 +21,6 @@ QEMUAccel noaccel = {
     .init_env = accel_nop,
     .flush_cache = accel_nop,
     .flush_page = accel_nop,
+    .info = noaccel_info,
 };
 
accel.h +8 -0
index 935cfef..549ce01 100644
@@ -1,11 +1,14 @@
 #ifndef _ACCEL_H_
 #define _ACCEL_H_
 
+#define MAX_INFO_BUF 1024
+
 typedef struct QEMUAccel {
     void (*cpu_interrupt)(CPUState *env);
     void (*init_env)(CPUState *env);
     void (*flush_cache)(CPUState *env, int global);
     void (*flush_page)(CPUState *env, target_ulong addr);
+    int (*info)(CPUState *env, char *buf);
 } QEMUAccel;
 
 extern QEMUAccel *current_accel;
@@ -35,4 +38,9 @@ static inline void accel_flush_page(CPUState *env, target_ulong addr)
 {
     current_accel->flush_page(env, addr);
 }
+
+static inline int accel_info(CPUState *env, char *buf)
+{
+    return current_accel->info(env, buf);
+}
 #endif
kqemu.c +26 -0
index 3f2433a..424d8f4 100644
@@ -1047,11 +1047,37 @@ static void qpi_init(void)
                                  0x1000, qpi_io_memory);
 }
 
+static int kqemu_info(CPUState *env, char *buf)
+{
+    int val, len;
+    int bufsiz = MAX_INFO_BUF;
+    val = 0;
+    val = env->kqemu_enabled;
+    len = snprintf(buf, bufsiz, "kqemu support: ");
+    buf += len;
+    bufsiz -= len;
+
+    switch(val) {
+    default:
+        len += snprintf(buf, bufsiz, "present, but bogus value\n");
+        break;
+    case 1:
+        len += snprintf(buf, bufsiz, "enabled for user code\n");
+        break;
+    case 2:
+        len += snprintf(buf, bufsiz, "enabled for user and kernel code\n");
+        break;
+    }
+
+    return len;
+}
+
 QEMUAccel kqemu_accel = {
     .cpu_interrupt = kqemu_cpu_interrupt,
     .init_env = kqemu_init_env,
     .flush_cache = kqemu_flush,
     .flush_page = kqemu_flush_page,
+    .info = kqemu_info,
 };
 
 #endif
monitor.c +12 -23
index f0a0bc3..d3ab137 100644
@@ -34,6 +34,7 @@
 #include "block.h"
 #include "audio/audio.h"
 #include "disas.h"
+#include "accel.h"
 #include <dirent.h>
 #include "qemu-timer.h"
 #include "migration.h"
@@ -1233,34 +1234,22 @@ static void mem_info(void)
 }
 #endif
 
-static void do_info_kqemu(void)
+static void do_info_accelerator(void)
 {
-#ifdef USE_KQEMU
+    char buf[MAX_INFO_BUF];
     CPUState *env;
-    int val;
-    val = 0;
+
     env = mon_get_cpu();
+
     if (!env) {
         term_printf("No cpu initialized yet");
         return;
     }
-    val = env->kqemu_enabled;
-    term_printf("kqemu support: ");
-    switch(val) {
-    default:
-    case 0:
-        term_printf("disabled\n");
-        break;
-    case 1:
-        term_printf("enabled for user code\n");
-        break;
-    case 2:
-        term_printf("enabled for user and kernel code\n");
-        break;
-    }
-#else
-    term_printf("kqemu support: not compiled\n");
-#endif
+
+    if (accel_info(env, buf))
+        term_printf(buf);
+    else
+        term_printf("No accelerator present\n");
 }
 
 #ifdef CONFIG_PROFILER
@@ -1493,8 +1482,8 @@ static const term_cmd_t info_cmds[] = {
 #endif
     { "jit", "", do_info_jit,
       "", "show dynamic compiler info", },
-    { "kqemu", "", do_info_kqemu,
-      "", "show kqemu information", },
+    { "accelerator", "", do_info_accelerator,
+      "", "show accelerator information", },
     { "usb", "", usb_info,
       "", "show guest USB devices", },
     { "usbhost", "", usb_host_info,
Signature · 1 line
1.5.5.1
#33 lore raw

[Qemu-devel] Re: [PATCH 10/32] turn info kqemu into generic info accelerator

Quoted 71 lines · Glauber Costa

From: Glauber Costa <[email protected]>

Yet another accel field: info.
From this point on, "info kqemu" is no more. "info accelerator" should be used instead.

---
 accel.c   |    6 ++++++
 accel.h   |    8 ++++++++
 kqemu.c   |   26 ++++++++++++++++++++++++++
 monitor.c |   35 ++++++++++++-----------------------
 4 files changed, 52 insertions(+), 23 deletions(-)
accel.c +6 -0
index 6776244..cb615d7 100644
@@ -8,6 +8,11 @@ int _accel_nop(void)
     return 0;
 }
 
+int noaccel_info(CPUState *env, char *buf)
+{
+    return snprintf(buf, MAX_INFO_BUF, "no accelerator present.\n");
+}
+
 #define accel_nop ((void *)_accel_nop)
 
 /* Accelerator wrapper for the no-accel (raw qemu) case */
@@ -16,5 +21,6 @@ QEMUAccel noaccel = {
     .init_env = accel_nop,
     .flush_cache = accel_nop,
     .flush_page = accel_nop,
+    .info = noaccel_info,
 };
 
accel.h +8 -0
index 935cfef..549ce01 100644
@@ -1,11 +1,14 @@
 #ifndef _ACCEL_H_
 #define _ACCEL_H_
 
+#define MAX_INFO_BUF 1024
+
 typedef struct QEMUAccel {
     void (*cpu_interrupt)(CPUState *env);
     void (*init_env)(CPUState *env);
     void (*flush_cache)(CPUState *env, int global);
     void (*flush_page)(CPUState *env, target_ulong addr);
+    int (*info)(CPUState *env, char *buf);
 } QEMUAccel;
 
 extern QEMUAccel *current_accel;
@@ -35,4 +38,9 @@ static inline void accel_flush_page(CPUState *env, target_ulong addr)
 {
     current_accel->flush_page(env, addr);
 }
+
+static inline int accel_info(CPUState *env, char *buf)
+{
+    return current_accel->info(env, buf);
+}
 #endif
kqemu.c +0 -0
index 3f2433a..424d8f4 100644

kqemu.c static void qpi_init(void) · line 1054

Quoted 8 lines
kqemu.c +4 -0
@@ -1047,11 +1047,37 @@ static void qpi_init(void)
                                  0x1000, qpi_io_memory);
 }
 
+static int kqemu_info(CPUState *env, char *buf)
+{
+    int val, len;
+    int bufsiz = MAX_INFO_BUF;
 

Why not just pass bufsiz as an argument to kqemu_info?

kqemu.c static void qpi_init(void) · line 1057

Quoted 3 lines
kqemu.c +2 -0
+    if (accel_info(env, buf))
+        term_printf(buf);
 

You should do term_printf("%s", buf); This is a common exploit if there's ever a chance that buf has user-originated data. Therefore, it's good practice to always use ("%s", buf) instead of passing buf directly.

Regards,

Anthony Liguori

#34 lore raw

[Qemu-devel] Re: [PATCH 10/32] turn info kqemu into generic info accelerator

Quoted 75 lines · Anthony Liguori
Quoted 74 lines · Glauber Costa

From: Glauber Costa <[email protected]>

Yet another accel field: info.
From this point on, "info kqemu" is no more. "info accelerator" should be used instead.

---
 accel.c   |    6 ++++++
 accel.h   |    8 ++++++++
 kqemu.c   |   26 ++++++++++++++++++++++++++
 monitor.c |   35 ++++++++++++-----------------------
 4 files changed, 52 insertions(+), 23 deletions(-)
accel.c +6 -0
index 6776244..cb615d7 100644
@@ -8,6 +8,11 @@ int _accel_nop(void)
     return 0;
 }
 
+int noaccel_info(CPUState *env, char *buf)
+{
+    return snprintf(buf, MAX_INFO_BUF, "no accelerator present.\n");
+}
+
 #define accel_nop ((void *)_accel_nop)
 
 /* Accelerator wrapper for the no-accel (raw qemu) case */
@@ -16,5 +21,6 @@ QEMUAccel noaccel = {
     .init_env = accel_nop,
     .flush_cache = accel_nop,
     .flush_page = accel_nop,
+    .info = noaccel_info,
 };
 
accel.h +8 -0
index 935cfef..549ce01 100644
@@ -1,11 +1,14 @@
 #ifndef _ACCEL_H_
 #define _ACCEL_H_
 
+#define MAX_INFO_BUF 1024
+
 typedef struct QEMUAccel {
     void (*cpu_interrupt)(CPUState *env);
     void (*init_env)(CPUState *env);
     void (*flush_cache)(CPUState *env, int global);
     void (*flush_page)(CPUState *env, target_ulong addr);
+    int (*info)(CPUState *env, char *buf);
 } QEMUAccel;
 
 extern QEMUAccel *current_accel;
@@ -35,4 +38,9 @@ static inline void accel_flush_page(CPUState *env, target_ulong addr)
 {
     current_accel->flush_page(env, addr);
 }
+
+static inline int accel_info(CPUState *env, char *buf)
+{
+    return current_accel->info(env, buf);
+}
 #endif
kqemu.c +0 -0
index 3f2433a..424d8f4 100644
@@ -1047,11 +1047,37 @@ static void qpi_init(void)
                                  0x1000, qpi_io_memory);
 }
 
Quoted 7 lines

kqemu.c static void qpi_init(void) · line 1082

Quoted 5 lines
kqemu.c +4 -0
+static int kqemu_info(CPUState *env, char *buf)
+{
+    int val, len;
+    int bufsiz = MAX_INFO_BUF;
 

Why not just pass bufsiz as an argument to kqemu_info?

ok, this makes sense.

thanks.

Quoted 13 lines

kqemu.c static void qpi_init(void) · line 1057

Quoted 4 lines
kqemu.c +2 -0
+    if (accel_info(env, buf))
+        term_printf(buf);
 

You should do term_printf("%s", buf); This is a common exploit if there's ever a chance that buf has user-originated data. Therefore, it's good practice to always use ("%s", buf) instead of passing buf directly.

Regards,

Anthony Liguori

#35 lore raw

PATCH 11/32 separate accelerator part of info profiler

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

Yet another accel field: profile.
It allows the accelerators to do part of the profiling their own way.

---
 accel.c   |    1 +
 accel.h   |    6 ++++++
 kqemu.c   |   35 +++++++++++++++++++++++++++++++++++
 monitor.c |   27 ++++++---------------------
 4 files changed, 48 insertions(+), 21 deletions(-)
accel.c +1 -0
index cb615d7..40dfac6 100644
@@ -22,5 +22,6 @@ QEMUAccel noaccel = {
     .flush_cache = accel_nop,
     .flush_page = accel_nop,
     .info = noaccel_info,
+    .profile = accel_nop,
 };
 
accel.h +6 -0
index 549ce01..bb56526 100644
@@ -9,6 +9,7 @@ typedef struct QEMUAccel {
     void (*flush_cache)(CPUState *env, int global);
     void (*flush_page)(CPUState *env, target_ulong addr);
     int (*info)(CPUState *env, char *buf);
+    int (*profile)(CPUState *env, char *buf);
 } QEMUAccel;
 
 extern QEMUAccel *current_accel;
@@ -43,4 +44,9 @@ static inline int accel_info(CPUState *env, char *buf)
 {
     return current_accel->info(env, buf);
 }
+
+static inline int accel_profile(CPUState *env, char *buf)
+{
+   return current_accel->profile(env, buf);
+}
 #endif
kqemu.c +35 -0
index 424d8f4..0a1d63b 100644
@@ -53,6 +53,10 @@
 #include "kqemu.h"
 #include "accel.h"
 
+#ifdef CONFIG_PROFILER
+#include "qemu-timer.h" /* for ticks_per_sec */
+#endif
+
 #ifdef _WIN32
 #define KQEMU_DEVICE "\\\\.\\kqemu"
 #else
@@ -1072,12 +1076,43 @@ static int kqemu_info(CPUState *env, char *buf)
     return len;
 }
 
+int64_t kqemu_time;
+int64_t kqemu_exec_count;
+int64_t kqemu_ret_int_count;
+int64_t kqemu_ret_excp_count;
+int64_t kqemu_ret_intr_count;
+extern int64_t qemu_time;
+
+static int kqemu_profile(CPUState *env, char *buf)
+{
+    int len = 0;
+#ifdef CONFIG_PROFILER
+    len = sprintf(buf, "kqemu time  %" PRId64 " (%0.3f %0.1f%%) count=%" PRId64
+                        " int=%" PRId64 " excp=%" PRId64 " intr=%" PRId64 "\n",
+                kqemu_time, kqemu_time / (double)ticks_per_sec,
+                kqemu_time / qemu_time * 100.0,
+                kqemu_exec_count,
+                kqemu_ret_int_count,
+                kqemu_ret_excp_count,
+                kqemu_ret_intr_count);
+
+    kqemu_time = 0;
+    kqemu_exec_count = 0;
+    kqemu_ret_int_count = 0;
+    kqemu_ret_excp_count = 0;
+    kqemu_ret_intr_count = 0;
+    kqemu_record_dump();
+#endif
+    return len;
+}
+
 QEMUAccel kqemu_accel = {
     .cpu_interrupt = kqemu_cpu_interrupt,
     .init_env = kqemu_init_env,
     .flush_cache = kqemu_flush,
     .flush_page = kqemu_flush_page,
     .info = kqemu_info,
+    .profile = kqemu_profile,
 };
 
 #endif
monitor.c +6 -21
index d3ab137..42a1b02 100644
@@ -1254,17 +1254,14 @@ static void do_info_accelerator(void)
 
 #ifdef CONFIG_PROFILER
 
-int64_t kqemu_time;
 int64_t qemu_time;
-int64_t kqemu_exec_count;
 int64_t dev_time;
-int64_t kqemu_ret_int_count;
-int64_t kqemu_ret_excp_count;
-int64_t kqemu_ret_intr_count;
-
 static void do_info_profile(void)
 {
     int64_t total;
+    char buf[MAX_BUF];
+    CPUState *env = mon_get_cpu();
+
     total = qemu_time;
     if (total == 0)
         total = 1;
@@ -1272,24 +1269,12 @@ static void do_info_profile(void)
                 dev_time, dev_time / (double)ticks_per_sec);
     term_printf("qemu time   %" PRId64 " (%0.3f)\n",
                 qemu_time, qemu_time / (double)ticks_per_sec);
-    term_printf("kqemu time  %" PRId64 " (%0.3f %0.1f%%) count=%" PRId64 " int=%" PRId64 " excp=%" PRId64 " intr=%" PRId64 "\n",
-                kqemu_time, kqemu_time / (double)ticks_per_sec,
-                kqemu_time / (double)total * 100.0,
-                kqemu_exec_count,
-                kqemu_ret_int_count,
-                kqemu_ret_excp_count,
-                kqemu_ret_intr_count);
+    if (accel_profile(env, buf))
+        term_printf(buf);
     qemu_time = 0;
-    kqemu_time = 0;
-    kqemu_exec_count = 0;
     dev_time = 0;
-    kqemu_ret_int_count = 0;
-    kqemu_ret_excp_count = 0;
-    kqemu_ret_intr_count = 0;
-#ifdef USE_KQEMU
-    kqemu_record_dump();
-#endif
 }
+
 #else
 static void do_info_profile(void)
 {
Signature · 1 line
1.5.5.1
#36 lore raw

PATCH 12/32 move kqemu externs to kqemu.h

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

move extern definitions to from cpu-all.h to kqemu.h. Just a step to increase kqemu's degree of separation.

---
 cpu-all.h |    5 -----
 kqemu.h   |    6 ++++++
 2 files changed, 6 insertions(+), 5 deletions(-)
cpu-all.h +0 -5
index cdd79bc..0150827 100644
@@ -1077,14 +1077,9 @@ static inline int64_t profile_getclock(void)
     return cpu_get_real_ticks();
 }
 
-extern int64_t kqemu_time, kqemu_time_start;
 extern int64_t qemu_time, qemu_time_start;
 extern int64_t tlb_flush_time;
-extern int64_t kqemu_exec_count;
 extern int64_t dev_time;
-extern int64_t kqemu_ret_int_count;
-extern int64_t kqemu_ret_excp_count;
-extern int64_t kqemu_ret_intr_count;
 #endif
 
 #endif /* CPU_ALL_H */
kqemu.h +6 -0
index ed25c75..1c7e024 100644
@@ -32,6 +32,12 @@
 
 #define KQEMU_VERSION 0x010400
 
+extern int64_t kqemu_time, kqemu_time_start;
+extern int64_t kqemu_exec_count;
+extern int64_t kqemu_ret_int_count;
+extern int64_t kqemu_ret_excp_count;
+extern int64_t kqemu_ret_intr_count;
+
 struct kqemu_segment_cache {
     uint16_t selector;
     uint16_t padding1;
Signature · 1 line
1.5.5.1
#37 lore raw

PATCH 13/32 move disabling code to kqemu.c instead of vl.c

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

kqemu is not smp. So instead of testing in vl.c, do the test in kqemu.c, and just refuse to start if smp_cpus > 1.

---
 kqemu.c |    2 +-
 vl.c    |    4 ----
 2 files changed, 1 insertions(+), 5 deletions(-)
kqemu.c +1 -1
index 0a1d63b..7f24cfc 100644
@@ -166,7 +166,7 @@ int kqemu_start(void)
     DWORD temp;
 #endif
 
-    if (!kqemu_allowed)
+    if (!kqemu_allowed || cpus > 1)
         return -1;
 
 #ifdef _WIN32
vl.c +0 -4
index adf5b25..f7bbfbb 100644
@@ -9469,10 +9469,6 @@ int main(int argc, char **argv)
         exit(1);
     }
 
-#ifdef USE_KQEMU
-    if (smp_cpus > 1)
-        kqemu_allowed = 0;
-#endif
     linux_boot = (kernel_filename != NULL);
     net_boot = (boot_devices_bitmap >> ('n' - 'a')) & 0xF;
 
Signature · 1 line
1.5.5.1
#38 lore raw

PATCH 14/32 set_notdirty goes through accel wrapper

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

Yet another accel field: set_notdirty

---
 accel.c    |    1 +
 accel.h    |    6 ++++++
 exec-all.h |    1 -
 exec.c     |   18 +++++++-----------
 kqemu.c    |    3 ++-
 5 files changed, 16 insertions(+), 13 deletions(-)
accel.c +1 -0
index 40dfac6..58ac053 100644
@@ -23,5 +23,6 @@ QEMUAccel noaccel = {
     .flush_page = accel_nop,
     .info = noaccel_info,
     .profile = accel_nop,
+    .set_notdirty = accel_nop,
 };
 
accel.h +6 -0
index bb56526..76e1f3b 100644
@@ -10,6 +10,7 @@ typedef struct QEMUAccel {
     void (*flush_page)(CPUState *env, target_ulong addr);
     int (*info)(CPUState *env, char *buf);
     int (*profile)(CPUState *env, char *buf);
+    void (*set_notdirty)(ram_addr_t addr);
 } QEMUAccel;
 
 extern QEMUAccel *current_accel;
@@ -49,4 +50,9 @@ static inline int accel_profile(CPUState *env, char *buf)
 {
    return current_accel->profile(env, buf);
 }
+
+static inline void accel_set_notdirty(target_ulong addr)
+{
+    current_accel->set_notdirty(addr);
+}
 #endif
exec-all.h +0 -1
index 2098fe8..cb2e7c6 100644
@@ -366,7 +366,6 @@ static inline int can_do_io(CPUState *env)
 #define MSR_QPI_COMMBASE 0xfabe0010
 
 int kqemu_cpu_exec(CPUState *env);
-void kqemu_set_notdirty(CPUState *env, ram_addr_t ram_addr);
 void kqemu_modify_page(CPUState *env, ram_addr_t ram_addr);
 void kqemu_set_phys_mem(uint64_t start_addr, ram_addr_t size, 
                         ram_addr_t phys_offset);
exec.c +7 -11
index 4f7aa67..fa62167 100644
@@ -1774,18 +1774,14 @@ void cpu_physical_memory_reset_dirty(ram_addr_t start, ram_addr_t end,
     if (length == 0)
         return;
     len = length >> TARGET_PAGE_BITS;
-#ifdef USE_KQEMU
-    /* XXX: should not depend on cpu context */
-    env = first_cpu;
-    if (env->kqemu_enabled) {
-        ram_addr_t addr;
-        addr = start;
-        for(i = 0; i < len; i++) {
-            kqemu_set_notdirty(env, addr);
-            addr += TARGET_PAGE_SIZE;
-        }
+
+    ram_addr_t addr;
+    addr = start;
+    for(i = 0; i < len; i++) {
+        accel_set_notdirty(addr);
+        addr += TARGET_PAGE_SIZE;
     }
-#endif
+
     mask = ~dirty_flags;
     p = phys_ram_dirty + (start >> TARGET_PAGE_BITS);
     for(i = 0; i < len; i++)
kqemu.c +2 -1
index 7f24cfc..98ec1a0 100644
@@ -275,7 +275,7 @@ static void kqemu_flush(CPUState *env, int global)
     nb_pages_to_flush = KQEMU_FLUSH_ALL;
 }
 
-void kqemu_set_notdirty(CPUState *env, ram_addr_t ram_addr)
+static void kqemu_set_notdirty(ram_addr_t ram_addr)
 {
 #ifdef DEBUG
     if (loglevel & CPU_LOG_INT) {
@@ -1113,6 +1113,7 @@ QEMUAccel kqemu_accel = {
     .flush_page = kqemu_flush_page,
     .info = kqemu_info,
     .profile = kqemu_profile,
+    .set_notdirty = kqemu_set_notdirty,
 };
 
 #endif
Signature · 1 line
1.5.5.1
#39 lore raw

PATCH 15/32 wrap modify_page through accel calls

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

Yet another accel field: modify_page

---
 accel.c    |    1 +
 accel.h    |    7 +++++++
 exec-all.h |    1 -
 exec.c     |   27 ++++++++++++---------------
 kqemu.c    |    5 ++++-
 5 files changed, 24 insertions(+), 17 deletions(-)
accel.c +1 -0
index 58ac053..d615912 100644
@@ -24,5 +24,6 @@ QEMUAccel noaccel = {
     .info = noaccel_info,
     .profile = accel_nop,
     .set_notdirty = accel_nop,
+    .modify_page = accel_nop,
 };
 
accel.h +7 -0
index 76e1f3b..e232f87 100644
@@ -11,6 +11,7 @@ typedef struct QEMUAccel {
     int (*info)(CPUState *env, char *buf);
     int (*profile)(CPUState *env, char *buf);
     void (*set_notdirty)(ram_addr_t addr);
+    void (*modify_page)(ram_addr_t addr, int dirty_flags);
 } QEMUAccel;
 
 extern QEMUAccel *current_accel;
@@ -55,4 +56,10 @@ static inline void accel_set_notdirty(target_ulong addr)
 {
     current_accel->set_notdirty(addr);
 }
+
+static inline void accel_modify_page(target_ulong addr, int dirty_flags)
+{
+    current_accel->modify_page(addr, dirty_flags);
+}
+
 #endif
exec-all.h +0 -1
index cb2e7c6..6c62f06 100644
@@ -366,7 +366,6 @@ static inline int can_do_io(CPUState *env)
 #define MSR_QPI_COMMBASE 0xfabe0010
 
 int kqemu_cpu_exec(CPUState *env);
-void kqemu_modify_page(CPUState *env, ram_addr_t ram_addr);
 void kqemu_set_phys_mem(uint64_t start_addr, ram_addr_t size, 
                         ram_addr_t phys_offset);
 void kqemu_record_dump(void);
exec.c +12 -15
index fa62167..089a91e 100644
@@ -2378,12 +2378,11 @@ static void notdirty_mem_writeb(void *opaque, target_phys_addr_t ram_addr,
         dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
 #endif
     }
+
     stb_p(phys_ram_base + ram_addr, val);
-#ifdef USE_KQEMU
-    if (cpu_single_env->kqemu_enabled &&
-        (dirty_flags & KQEMU_MODIFY_PAGE_MASK) != KQEMU_MODIFY_PAGE_MASK)
-        kqemu_modify_page(cpu_single_env, ram_addr);
-#endif
+
+    accel_modify_page(ram_addr, dirty_flags);
+
     dirty_flags |= (0xff & ~CODE_DIRTY_FLAG);
     phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS] = dirty_flags;
     /* we remove the notdirty callback only if the code has been
@@ -2403,12 +2402,11 @@ static void notdirty_mem_writew(void *opaque, target_phys_addr_t ram_addr,
         dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
 #endif
     }
+
     stw_p(phys_ram_base + ram_addr, val);
-#ifdef USE_KQEMU
-    if (cpu_single_env->kqemu_enabled &&
-        (dirty_flags & KQEMU_MODIFY_PAGE_MASK) != KQEMU_MODIFY_PAGE_MASK)
-        kqemu_modify_page(cpu_single_env, ram_addr);
-#endif
+
+    accel_modify_page(ram_addr, dirty_flags);
+
     dirty_flags |= (0xff & ~CODE_DIRTY_FLAG);
     phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS] = dirty_flags;
     /* we remove the notdirty callback only if the code has been
@@ -2428,12 +2426,11 @@ static void notdirty_mem_writel(void *opaque, target_phys_addr_t ram_addr,
         dirty_flags = phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS];
 #endif
     }
+
     stl_p(phys_ram_base + ram_addr, val);
-#ifdef USE_KQEMU
-    if (cpu_single_env->kqemu_enabled &&
-        (dirty_flags & KQEMU_MODIFY_PAGE_MASK) != KQEMU_MODIFY_PAGE_MASK)
-        kqemu_modify_page(cpu_single_env, ram_addr);
-#endif
+
+    accel_modify_page(ram_addr, dirty_flags);
+
     dirty_flags |= (0xff & ~CODE_DIRTY_FLAG);
     phys_ram_dirty[ram_addr >> TARGET_PAGE_BITS] = dirty_flags;
     /* we remove the notdirty callback only if the code has been
kqemu.c +4 -1
index 98ec1a0..5777afd 100644
@@ -304,7 +304,7 @@ static void kqemu_reset_modified_ram_pages(void)
     nb_modified_ram_pages = 0;
 }
 
-void kqemu_modify_page(CPUState *env, ram_addr_t ram_addr)
+static void kqemu_modify_page(ram_addr_t ram_addr, int dirty_flags)
 {
     unsigned long page_index;
     int ret;
@@ -312,6 +312,8 @@ void kqemu_modify_page(CPUState *env, ram_addr_t ram_addr)
     DWORD temp;
 #endif
 
+    if ((dirty_flags & KQEMU_MODIFY_PAGE_MASK) != KQEMU_MODIFY_PAGE_MASK)
+        return;
     page_index = ram_addr >> TARGET_PAGE_BITS;
     if (!modified_ram_pages_table[page_index]) {
 #if 0
@@ -1114,6 +1116,7 @@ QEMUAccel kqemu_accel = {
     .info = kqemu_info,
     .profile = kqemu_profile,
     .set_notdirty = kqemu_set_notdirty,
+    .modify_page = kqemu_modify_page,
 };
 
 #endif
Signature · 1 line
1.5.5.1
#40 lore raw

PATCH 16/32 remove kqemu reference from hw/pc.c

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

Instead, route cpu_get_ticks through accel driver.

---
 accel.c |    3 +++
 accel.h |   12 ++++++++++++
 hw/pc.c |   13 ++-----------
 kqemu.c |    6 ++++++
 4 files changed, 23 insertions(+), 11 deletions(-)
accel.c +3 -0
index d615912..08a85c2 100644
@@ -25,5 +25,8 @@ QEMUAccel noaccel = {
     .profile = accel_nop,
     .set_notdirty = accel_nop,
     .modify_page = accel_nop,
+#ifndef CONFIG_USER_ONLY
+    .get_real_ticks = cpu_get_ticks,
+#endif
 };
 
accel.h +12 -0
index e232f87..cf0d752 100644
@@ -12,6 +12,9 @@ typedef struct QEMUAccel {
     int (*profile)(CPUState *env, char *buf);
     void (*set_notdirty)(ram_addr_t addr);
     void (*modify_page)(ram_addr_t addr, int dirty_flags);
+#ifndef CONFIG_USER_ONLY
+    uint64_t (*get_real_ticks)(void);
+#endif
 } QEMUAccel;
 
 extern QEMUAccel *current_accel;
@@ -62,4 +65,13 @@ static inline void accel_modify_page(target_ulong addr, int dirty_flags)
     current_accel->modify_page(addr, dirty_flags);
 }
 
+int64_t cpu_get_ticks(void);
+
+#ifndef CONFIG_USER_ONLY
+static inline uint64_t accel_get_real_ticks(void)
+{
+   return current_accel->get_real_ticks();
+}
+#endif
+
 #endif
hw/pc.c +2 -11
index 34683e7..2f56c1f 100644
@@ -33,6 +33,7 @@
 #include "boards.h"
 #include "console.h"
 #include "fw_cfg.h"
+#include "accel.h"
 
 /* output Bochs bios info messages */
 //#define DEBUG_BIOS
@@ -75,17 +76,7 @@ static void ioportF0_write(void *opaque, uint32_t addr, uint32_t data)
 /* TSC handling */
 uint64_t cpu_get_tsc(CPUX86State *env)
 {
-    /* Note: when using kqemu, it is more logical to return the host TSC
-       because kqemu does not trap the RDTSC instruction for
-       performance reasons */
-#ifdef USE_KQEMU
-    if (env->kqemu_enabled) {
-        return cpu_get_real_ticks();
-    } else
-#endif
-    {
-        return cpu_get_ticks();
-    }
+    return accel_get_real_ticks();
 }
 
 /* SMM support */
kqemu.c +6 -0
index 5777afd..6bce892 100644
@@ -1117,6 +1117,12 @@ QEMUAccel kqemu_accel = {
     .profile = kqemu_profile,
     .set_notdirty = kqemu_set_notdirty,
     .modify_page = kqemu_modify_page,
+#ifndef CONFIG_USER_ONLY
+    /* Note: when using kqemu, it is more logical to return the host TSC
+       because kqemu does not trap the RDTSC instruction for
+       performance reasons */
+    .get_real_ticks = cpu_get_real_ticks,
+#endif
 };
 
 #endif
Signature · 1 line
1.5.5.1
#41 lore raw

PATCH 17/32 build list of available accelerators

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

instead of hardcoding kqemu_start() in exec.c, which would require such a hack for all available accelerators, semantics of register_qemu_accel() is changed a little bit. It only builds a list of available accelerators. The last one registered is the first tried.

This is a temporary solution, since we don't control exactly the order in which things are loaded by the constructor attributes. The final goal is to have command line switches and priority lists to determine that.

"info accelerator" is changed to accomodate it. It now prints a list of available accelerators, and only if one of them is active, a detailed description of it is printed.

---
 accel.c   |    3 ++
 accel.h   |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 exec.c    |    3 --
 kqemu.c   |    5 ++-
 monitor.c |   12 +++++++++-
 vl.c      |    7 ++++++
 6 files changed, 84 insertions(+), 9 deletions(-)
accel.c +3 -0
index 08a85c2..74f7c89 100644
@@ -2,6 +2,7 @@
 #include "accel.h"
 
 QEMUAccel *current_accel;
+QEMUCont *head = NULL;
 
 int _accel_nop(void)
 {
@@ -17,8 +18,10 @@ int noaccel_info(CPUState *env, char *buf)
 
 /* Accelerator wrapper for the no-accel (raw qemu) case */
 QEMUAccel noaccel = {
+    .name = "none",
     .cpu_interrupt = accel_nop,
     .init_env = accel_nop,
+    .start = accel_nop,
     .flush_cache = accel_nop,
     .flush_page = accel_nop,
     .info = noaccel_info,
accel.h +61 -2

87 lines not on this page · raw message

exec.c +0 -3
index 089a91e..005785a 100644
@@ -497,9 +497,6 @@ void cpu_exec_init_all(unsigned long tb_size)
 #if !defined(CONFIG_USER_ONLY)
     io_mem_init();
 #endif
-#ifdef USE_KQEMU
-    kqemu_start();
-#endif
 }
 
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
kqemu.c +3 -2
index 6bce892..68ec917 100644
@@ -158,7 +158,7 @@ static void kqemu_update_cpuid(CPUState *env)
 
 QEMUAccel kqemu_accel;
 
-int kqemu_start(void)
+static int kqemu_start(int cpus)
 {
     struct kqemu_init kinit;
     int ret, version;
@@ -240,7 +240,6 @@ int kqemu_start(void)
     }
     nb_pages_to_flush = 0;
     nb_ram_pages_to_update = 0;
-    register_qemu_accel(&kqemu_accel);
 
     qpi_init();
     return 0;
@@ -1109,8 +1108,10 @@ static int kqemu_profile(CPUState *env, char *buf)
 }
 
 QEMUAccel kqemu_accel = {
+    .name = "KQEMU",
     .cpu_interrupt = kqemu_cpu_interrupt,
     .init_env = kqemu_init_env,
+    .start = kqemu_start,
     .flush_cache = kqemu_flush,
     .flush_page = kqemu_flush_page,
     .info = kqemu_info,
monitor.c +10 -2
index 42a1b02..fe915d8 100644
@@ -1234,6 +1234,15 @@ static void mem_info(void)
 }
 #endif
 
+static int do_accel_do_list(void)
+{
+    QEMUCont *tmp;
+    for (tmp= get_accel_head(); tmp != NULL; tmp = tmp->next)
+    {
+        term_printf("%c %s\n", tmp->active ? '*' : ' ', tmp->acc->name);
+    }
+}
+
 static void do_info_accelerator(void)
 {
     char buf[MAX_INFO_BUF];
@@ -1246,10 +1255,9 @@ static void do_info_accelerator(void)
         return;
     }
 
+    do_accel_do_list();
     if (accel_info(env, buf))
         term_printf(buf);
-    else
-        term_printf("No accelerator present\n");
 }
 
 #ifdef CONFIG_PROFILER
vl.c +7 -0
index f7bbfbb..c584ea3 100644
@@ -140,6 +140,7 @@
 #include "disas.h"
 
 #include "exec-all.h"
+#include "accel.h"
 
 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
 #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
@@ -8815,6 +8816,7 @@ int main(int argc, char **argv)
     }
 #endif
 
+    register_qemu_accel(&kqemu_accel);
     register_qemu_accel(&noaccel);
 
     register_machines();
@@ -9589,6 +9591,11 @@ int main(int argc, char **argv)
     /* init the dynamic translator */
     cpu_exec_init_all(tb_size * 1024 * 1024);
 
+    if (accel_start(smp_cpus)) {
+	    fprintf(stderr, "qemu: error, no suitable accelerator found\n");
+	    exit(1);
+    }
+
     bdrv_init();
 
     /* we always create the cdrom drive, even if no disk is there */
Signature · 1 line
1.5.5.1
#42 lore raw

[Qemu-devel] Re: [PATCH 17/32] build list of available accelerators

Quoted 11 lines · Glauber Costa

From: Glauber Costa <[email protected]>

instead of hardcoding kqemu_start() in exec.c, which would require such a hack for all available accelerators, semantics of register_qemu_accel() is changed a little bit. It only builds a list of available accelerators. The last one registered is the first tried.

This is a temporary solution, since we don't control exactly the order in which things are loaded by the constructor attributes. The final goal is to have command line switches and priority lists to determine that.

Quoted 8 lines

"info accelerator" is changed to accomodate it. It now prints a list of available accelerators, and only if one of them is active, a detailed description of it is printed.

#define MAX_INFO_BUF 1024

typedef struct QEMUAccel {
+ char *name;

const, or warnings you get.

accel.h typedef struct QEMUAccel { · line 26

Quoted 7 lines
accel.h +5 -0
+typedef struct QEMUCont {
+    QEMUAccel *acc;
+    int active;
+    struct QEMUCont *next;
+} QEMUCont;

The name is unclear. But you could fold the structure into QEMUAccel, no?

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#43 lore raw

[Qemu-devel] Re: [PATCH 17/32] build list of available accelerators

Quoted 22 lines · Avi Kivity
Quoted 11 lines · Glauber Costa

From: Glauber Costa <[email protected]>

instead of hardcoding kqemu_start() in exec.c, which would require such a hack for all available accelerators, semantics of register_qemu_accel() is changed a little bit. It only builds a list of available accelerators. The last one registered is the first tried.

This is a temporary solution, since we don't control exactly the order in which things are loaded by the constructor attributes. The final goal is to have command line switches and priority lists to determine that.

Quoted 7 lines

"info accelerator" is changed to accomodate it. It now prints a list of available accelerators, and only if one of them is active, a detailed description of it is printed.

#define MAX_INFO_BUF 1024
typedef struct QEMUAccel {
+ char *name;

const, or warnings you get.

Quoted 8 lines

accel.h typedef struct QEMUAccel { · line 26

Quoted 6 lines

+typedef struct QEMUCont {

accel.h +4 -0
+    QEMUAccel *acc;
+    int active;
+    struct QEMUCont *next;
+} QEMUCont;

The name is unclear. But you could fold the structure into QEMUAccel, no?

Yes, it was folded in my first version. It is separated just to allow external accelerators to register themselves without messing with the accelerator list, which would be internal. But I'm probably just being overzealous.

Quoted 5 lines
Signature · 3 lines
-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#44 lore raw

[Qemu-devel] Re: [PATCH 17/32] build list of available accelerators

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

+typedef struct QEMUCont {

accel.h +4 -0
+    QEMUAccel *acc;
+    int active;
+    struct QEMUCont *next;
+} QEMUCont;
Quoted 7 lines
Quoted 2 lines

The name is unclear. But you could fold the structure into QEMUAccel, no?

Yes, it was folded in my first version. It is separated just to allow external accelerators to register themselves without messing with the accelerator list, which would be internal. But I'm probably just being overzealous.

You could still have a registration function. The accelerator itself would not need to touch the members.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#45 lore raw

PATCH 18/32 provide --accel option

In reply to Glauber Costa

The --accel option will provide us the ability of defining which accelerator to pick at run time. It has the advantage of not using the not-well-accepted constructor directives, and also, of stabilishing a way to define priorities among accelerators.

The ones registered first, are tried first.

---
 vl.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)
vl.c +21 -3
index c584ea3..964205d 100644
@@ -255,6 +255,13 @@ static QEMUTimer *icount_vm_timer;
 
 uint8_t qemu_uuid[16];
 
+QEMUAccel *available_accels[] = {
+/* list of available accelerators */
+#ifdef USE_KQEMU
+    &kqemu_accel,
+#endif
+};
+
 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
 
 /***********************************************************/
@@ -8355,6 +8362,7 @@ enum {
     QEMU_OPTION_no_quit,
     QEMU_OPTION_pidfile,
     QEMU_OPTION_no_kqemu,
+    QEMU_OPTION_accel,
     QEMU_OPTION_kernel_kqemu,
     QEMU_OPTION_win2k_hack,
     QEMU_OPTION_usb,
@@ -8442,6 +8450,7 @@ static const QEMUOption qemu_options[] = {
     { "no-kqemu", 0, QEMU_OPTION_no_kqemu },
     { "kernel-kqemu", 0, QEMU_OPTION_kernel_kqemu },
 #endif
+    { "accel", HAS_ARG, QEMU_OPTION_accel},
 #if defined(TARGET_PPC) || defined(TARGET_SPARC)
     { "g", 1, QEMU_OPTION_g },
 #endif
@@ -8816,9 +8825,6 @@ int main(int argc, char **argv)
     }
 #endif
 
-    register_qemu_accel(&kqemu_accel);
-    register_qemu_accel(&noaccel);
-
     register_machines();
     machine = first_machine;
     cpu_model = NULL;
@@ -9267,6 +9273,15 @@ int main(int argc, char **argv)
                 kqemu_allowed = 2;
                 break;
 #endif
+            case QEMU_OPTION_accel:
+                {
+                    int i;
+                    for (i = 0; i < ARRAY_SIZE(available_accels); i++) {
+                        if (!strcasecmp(optarg, available_accels[i]->name))
+                            register_qemu_accel(available_accels[i]);
+                    }
+                }
+                break;
             case QEMU_OPTION_usb:
                 usb_enabled = 1;
                 break;
@@ -9408,6 +9423,9 @@ int main(int argc, char **argv)
         exit(1);
     }
 
+    /* Basic handler for the noaccel case */
+    register_qemu_accel(&noaccel);
+
     if (nographic) {
        if (serial_device_index == 0)
            serial_devices[0] = "stdio";
Signature · 1 line
1.5.5.1
#46 lore raw

PATCH 19/32 add hook to cpu_register_physical_memory

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

kqemu has a hook in it, so add an accel wrapper. However, we still provide a double underlined version which does not call the wrapper. That's basically because kqemu call cpu_register_physical_memory itself during its initialization.

---
 accel.c   |    1 +
 accel.h   |    9 +++++++++
 cpu-all.h |    4 ++++
 exec.c    |   32 +++++++++++++++++++-------------
 kqemu.c   |    3 ++-
 5 files changed, 35 insertions(+), 14 deletions(-)
accel.c +1 -0
index 74f7c89..bf1194d 100644
@@ -31,5 +31,6 @@ QEMUAccel noaccel = {
 #ifndef CONFIG_USER_ONLY
     .get_real_ticks = cpu_get_ticks,
 #endif
+    .register_physical_memory = accel_nop,
 };
 
accel.h +9 -0
index 3e49a93..dbb6372 100644
@@ -17,6 +17,9 @@ typedef struct QEMUAccel {
 #ifndef CONFIG_USER_ONLY
     uint64_t (*get_real_ticks)(void);
 #endif
+    void (*register_physical_memory)(uint64_t start_addr,
+                                     ram_addr_t size, ram_addr_t phys_offset);
+
 } QEMUAccel;
 
 typedef struct QEMUCont {
@@ -133,4 +136,10 @@ static inline uint64_t accel_get_real_ticks(void)
 }
 #endif
 
+static inline void accel_register_phys_mem(uint64_t start_addr,
+                                           ram_addr_t size,
+                                           ram_addr_t phys_offset)
+{
+    current_accel->register_physical_memory(start_addr, size, phys_offset);
+}
 #endif
cpu-all.h +4 -0
index 0150827..edefb45 100644
@@ -863,6 +863,10 @@ extern ram_addr_t ram_size;
 typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, uint32_t value);
 typedef uint32_t CPUReadMemoryFunc(void *opaque, target_phys_addr_t addr);
 
+/* this is a private version, meant for internal use of accelerators */
+void __cpu_register_physical_memory(target_phys_addr_t start_addr,
+                                  ram_addr_t size,
+                                  ram_addr_t phys_offset);
 void cpu_register_physical_memory(target_phys_addr_t start_addr,
                                   ram_addr_t size,
                                   ram_addr_t phys_offset);
exec.c +19 -13
index 005785a..80b8a78 100644
@@ -2183,12 +2183,13 @@ static void *subpage_init (target_phys_addr_t base, ram_addr_t *phys,
         }                                                               \
     } while (0)
 
-/* register physical memory. 'size' must be a multiple of the target
-   page size. If (phys_offset & ~TARGET_PAGE_MASK) != 0, then it is an
-   io memory page */
-void cpu_register_physical_memory(target_phys_addr_t start_addr,
-                                  ram_addr_t size,
-                                  ram_addr_t phys_offset)
+/* Use this version of cpu registering physical memory in accel-specific code. It exists
+ * to avoid chicken and egg problems with code that might need to register memory in qemu,
+ * but not with the underlying accelerator
+ */
+void __cpu_register_physical_memory(target_phys_addr_t start_addr,
+                                    ram_addr_t size,
+                                    ram_addr_t phys_offset)
 {
     target_phys_addr_t addr, end_addr;
     PhysPageDesc *p;
@@ -2196,13 +2197,6 @@ void cpu_register_physical_memory(target_phys_addr_t start_addr,
     ram_addr_t orig_size = size;
     void *subpage;
 
-#ifdef USE_KQEMU
-    /* XXX: should not depend on cpu context */
-    env = first_cpu;
-    if (env && env->kqemu_enabled) {
-        kqemu_set_phys_mem(start_addr, size, phys_offset);
-    }
-#endif
     size = (size + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
     end_addr = start_addr + (target_phys_addr_t)size;
     for(addr = start_addr; addr != end_addr; addr += TARGET_PAGE_SIZE) {
@@ -2260,6 +2254,18 @@ void cpu_register_physical_memory(target_phys_addr_t start_addr,
     }
 }
 
+/* register physical memory. 'size' must be a multiple of the target
+   page size. If (phys_offset & ~TARGET_PAGE_MASK) != 0, then it is an
+   io memory page */
+void cpu_register_physical_memory(target_phys_addr_t start_addr,
+                                  ram_addr_t size,
+                                  ram_addr_t phys_offset)
+{
+    accel_register_phys_mem(start_addr, size, phys_offset);
+
+    __cpu_register_physical_memory(start_addr, size, phys_offset);
+}
+
 /* XXX: temporary until new memory mapping API */
 ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr)
 {
kqemu.c +2 -1
index 68ec917..f4d905a 100644
@@ -1048,7 +1048,7 @@ static void qpi_init(void)
     qpi_io_memory = cpu_register_io_memory(0, 
                                            qpi_mem_read, 
                                            qpi_mem_write, NULL);
-    cpu_register_physical_memory(kqemu_comm_base & ~0xfff, 
+    __cpu_register_physical_memory(kqemu_comm_base & ~0xfff,
                                  0x1000, qpi_io_memory);
 }
 
@@ -1124,6 +1124,7 @@ QEMUAccel kqemu_accel = {
        performance reasons */
     .get_real_ticks = cpu_get_real_ticks,
 #endif
+    .register_physical_memory = kqemu_set_phys_mem,
 };
 
 #endif
Signature · 1 line
1.5.5.1
#47 lore raw

PATCH 20/32 accel_trace_io

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

kqemu keeps trace of the last io done. Do it through an accel_wrapper.

---
 accel.c            |    2 ++
 accel.h            |   13 ++++++++++++-
 cpu-exec.c         |    9 ++-------
 kqemu.c            |   18 ++++++++++++++++++
 softmmu_template.h |   10 ++++------
 vl.c               |   30 ++++++------------------------
 6 files changed, 44 insertions(+), 38 deletions(-)
accel.c +2 -0
index bf1194d..0890039 100644
@@ -32,5 +32,7 @@ QEMUAccel noaccel = {
     .get_real_ticks = cpu_get_ticks,
 #endif
     .register_physical_memory = accel_nop,
+    .trace_io = accel_nop,
+    .break_loop = accel_nop,
 };
 
accel.h +12 -1
index dbb6372..b37175b 100644
@@ -19,7 +19,8 @@ typedef struct QEMUAccel {
 #endif
     void (*register_physical_memory)(uint64_t start_addr,
                                      ram_addr_t size, ram_addr_t phys_offset);
-
+    void (*trace_io)(CPUState *env);
+    int (*break_loop)(CPUState *env);
 } QEMUAccel;
 
 typedef struct QEMUCont {
@@ -142,4 +143,14 @@ static inline void accel_register_phys_mem(uint64_t start_addr,
 {
     current_accel->register_physical_memory(start_addr, size, phys_offset);
 }
+
+static inline void accel_trace_io(CPUState *env)
+{
+    current_accel->trace_io(env);
+}
+
+static inline int accel_break_loop(CPUState *env)
+{
+    return current_accel->break_loop(env);
+}
 #endif
cpu-exec.c +2 -7
index 88b7d6f..18908d5 100644
@@ -36,6 +36,7 @@
 #include <signal.h>
 #include <sys/ucontext.h>
 #endif
+#include "accel.h"
 
 #if defined(__sparc__) && !defined(HOST_SOLARIS)
 // Work around ugly bugs in glibc that mangle global register contents
@@ -646,13 +647,7 @@ int cpu_exec(CPUState *env1)
                 }
                 /* reset soft MMU for next block (it can currently
                    only be set by a memory fault) */
-#if defined(USE_KQEMU)
-#define MIN_CYCLE_BEFORE_SWITCH (100 * 1000)
-                if (kqemu_is_ok(env) &&
-                    (cpu_get_time_fast() - env->last_io_time) >= MIN_CYCLE_BEFORE_SWITCH) {
-                    cpu_loop_exit();
-                }
-#endif
+                accel_break_loop(env);
             } /* for(;;) */
         } else {
             env_to_regs();
kqemu.c +18 -0
index f4d905a..d38d0e3 100644
@@ -1107,6 +1107,22 @@ static int kqemu_profile(CPUState *env, char *buf)
     return len;
 }
 
+static void kqemu_trace_io(CPUState *env)
+{
+    if (env)
+        env->last_io_time = cpu_get_time_fast();
+}
+
+static int kqemu_break_loop(CPUState *env)
+{
+#define MIN_CYCLE_BEFORE_SWITCH (100 * 1000)
+    if (kqemu_is_ok(env) &&
+        (cpu_get_time_fast() - env->last_io_time) >= MIN_CYCLE_BEFORE_SWITCH) {
+        return 1;
+    }
+    return 0;
+}
+
 QEMUAccel kqemu_accel = {
     .name = "KQEMU",
     .cpu_interrupt = kqemu_cpu_interrupt,
@@ -1125,6 +1141,8 @@ QEMUAccel kqemu_accel = {
     .get_real_ticks = cpu_get_real_ticks,
 #endif
     .register_physical_memory = kqemu_set_phys_mem,
+    .trace_io = kqemu_trace_io,
+    .break_loop = kqemu_break_loop,
 };
 
 #endif
softmmu_template.h +4 -6
index 98dd378..4945352 100644
@@ -47,6 +47,8 @@
 #define ADDR_READ addr_read
 #endif
 
+#include "accel.h"
+
 static DATA_TYPE glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(target_ulong addr,
                                                         int mmu_idx,
                                                         void *retaddr);
@@ -75,9 +77,7 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(target_phys_addr_t physaddr,
     res |= (uint64_t)io_mem_read[index][2](io_mem_opaque[index], physaddr + 4) << 32;
 #endif
 #endif /* SHIFT > 2 */
-#ifdef USE_KQEMU
-    env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
     return res;
 }
 
@@ -220,9 +220,7 @@ static inline void glue(io_write, SUFFIX)(target_phys_addr_t physaddr,
     io_mem_write[index][2](io_mem_opaque[index], physaddr + 4, val >> 32);
 #endif
 #endif /* SHIFT > 2 */
-#ifdef USE_KQEMU
-    env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
 }
 
 void REGPARM glue(glue(__st, SUFFIX), MMUSUFFIX)(target_ulong addr,
vl.c +6 -24
index 964205d..e64becb 100644
@@ -420,10 +420,7 @@ void cpu_outb(CPUState *env, int addr, int val)
         fprintf(logfile, "outb: %04x %02x\n", addr, val);
 #endif
     ioport_write(0, addr, val);
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
 }
 
 void cpu_outw(CPUState *env, int addr, int val)
@@ -433,10 +430,7 @@ void cpu_outw(CPUState *env, int addr, int val)
         fprintf(logfile, "outw: %04x %04x\n", addr, val);
 #endif
     ioport_write(1, addr, val);
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
 }
 
 void cpu_outl(CPUState *env, int addr, int val)
@@ -446,10 +440,7 @@ void cpu_outl(CPUState *env, int addr, int val)
         fprintf(logfile, "outl: %04x %08x\n", addr, val);
 #endif
     ioport_write(2, addr, val);
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
 }
 
 int cpu_inb(CPUState *env, int addr)
@@ -460,10 +451,7 @@ int cpu_inb(CPUState *env, int addr)
     if (loglevel & CPU_LOG_IOPORT)
         fprintf(logfile, "inb : %04x %02x\n", addr, val);
 #endif
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
     return val;
 }
 
@@ -475,10 +463,7 @@ int cpu_inw(CPUState *env, int addr)
     if (loglevel & CPU_LOG_IOPORT)
         fprintf(logfile, "inw : %04x %04x\n", addr, val);
 #endif
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
     return val;
 }
 
@@ -490,10 +475,7 @@ int cpu_inl(CPUState *env, int addr)
     if (loglevel & CPU_LOG_IOPORT)
         fprintf(logfile, "inl : %04x %08x\n", addr, val);
 #endif
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
     return val;
 }
 
Signature · 1 line
1.5.5.1
#48 lore raw

[Qemu-devel] Re: [PATCH 20/32] accel_trace_io

Quoted 5 lines · Glauber Costa

From: Glauber Costa <[email protected]>

kqemu keeps trace of the last io done. Do it through an accel_wrapper.

The hooks here are probably not the best they could be. The purpose of this code in kqemu, from what I can tell, is to control how long we run in softmmu before trying to run in the kernel again. I presume this is mainly for kernel-kqemu.

When kernel-kqemu encounters an instruction it can't handle, it drops to userspace and runs in softmmu for a while. The question is how long should it run in softmmu and this is a heuristic. This is what the code is doing.

Regards,

Anthony Liguori

#49 lore raw

[Qemu-devel] Re: [PATCH 20/32] accel_trace_io

Quoted 15 lines · ----- "Anthony Liguori
Quoted 5 lines · Glauber Costa

From: Glauber Costa <[email protected]>

kqemu keeps trace of the last io done. Do it through an accel_wrapper.

The hooks here are probably not the best they could be. The purpose of
this code in kqemu, from what I can tell, is to control how long we run
in softmmu before trying to run in the kernel again. I presume this is
mainly for kernel-kqemu.

Quoted 8 lines

When kernel-kqemu encounters an instruction it can't handle, it drops to
userspace and runs in softmmu for a while. The question is how long should it run in softmmu and this is a heuristic. This is what the code
is doing.

Regards,

My proposal is:

* add a hook for in and another for out operations. It's generic enough to be useful for other purposes in the future. KVM does not need to do anything in here, and kqemu can just record the last io time
* add a hook at th end of cpu_exec, that allows the accel to shut off current execution based on any criteria it wants to. accel_break_loop (the current one) seems a fine name for it. To be even more explicit, the accel can just return 1 or 0 indicating whether or not the current execution loop should be stopped, and cpu_loop_exit() is called based on the return value.

What do you think?

#50 lore raw

Re: [Qemu-devel] [PATCH 20/32] accel_trace_io

In reply to Glauber Costa

2008/10/23 Glauber Costa <[email protected]>:

Quoted 219 lines

From: Glauber Costa <[email protected]>

kqemu keeps trace of the last io done. Do it through an accel_wrapper.

---
 accel.c            |    2 ++
 accel.h            |   13 ++++++++++++-
 cpu-exec.c         |    9 ++-------
 kqemu.c            |   18 ++++++++++++++++++
 softmmu_template.h |   10 ++++------
 vl.c               |   30 ++++++------------------------
 6 files changed, 44 insertions(+), 38 deletions(-)
accel.c +2 -0
index bf1194d..0890039 100644
@@ -32,5 +32,7 @@ QEMUAccel noaccel = {
    .get_real_ticks = cpu_get_ticks,
 #endif
    .register_physical_memory = accel_nop,
+    .trace_io = accel_nop,
+    .break_loop = accel_nop,
 };
 
accel.h +12 -1
index dbb6372..b37175b 100644
@@ -19,7 +19,8 @@ typedef struct QEMUAccel {
 #endif
    void (*register_physical_memory)(uint64_t start_addr,
                                     ram_addr_t size, ram_addr_t phys_offset);
-
+    void (*trace_io)(CPUState *env);
+    int (*break_loop)(CPUState *env);
 } QEMUAccel;
 
 typedef struct QEMUCont {
@@ -142,4 +143,14 @@ static inline void accel_register_phys_mem(uint64_t start_addr,
 {
    current_accel->register_physical_memory(start_addr, size, phys_offset);
 }
+
+static inline void accel_trace_io(CPUState *env)
+{
+    current_accel->trace_io(env);
+}
+
+static inline int accel_break_loop(CPUState *env)
+{
+    return current_accel->break_loop(env);
+}
 #endif
cpu-exec.c +2 -7
index 88b7d6f..18908d5 100644
@@ -36,6 +36,7 @@
 #include <signal.h>
 #include <sys/ucontext.h>
 #endif
+#include "accel.h"
 
 #if defined(__sparc__) && !defined(HOST_SOLARIS)
 // Work around ugly bugs in glibc that mangle global register contents
@@ -646,13 +647,7 @@ int cpu_exec(CPUState *env1)
                }
                /* reset soft MMU for next block (it can currently
                   only be set by a memory fault) */
-#if defined(USE_KQEMU)
-#define MIN_CYCLE_BEFORE_SWITCH (100 * 1000)
-                if (kqemu_is_ok(env) &&
-                    (cpu_get_time_fast() - env->last_io_time) >= MIN_CYCLE_BEFORE_SWITCH) {
-                    cpu_loop_exit();
-                }
-#endif
+                accel_break_loop(env);
            } /* for(;;) */
        } else {
            env_to_regs();
kqemu.c +18 -0
index f4d905a..d38d0e3 100644
@@ -1107,6 +1107,22 @@ static int kqemu_profile(CPUState *env, char *buf)
    return len;
 }
 
+static void kqemu_trace_io(CPUState *env)
+{
+    if (env)
+        env->last_io_time = cpu_get_time_fast();
+}
+
+static int kqemu_break_loop(CPUState *env)
+{
+#define MIN_CYCLE_BEFORE_SWITCH (100 * 1000)
+    if (kqemu_is_ok(env) &&
+        (cpu_get_time_fast() - env->last_io_time) >= MIN_CYCLE_BEFORE_SWITCH) {
+        return 1;
+    }
+    return 0;
+}
+
 QEMUAccel kqemu_accel = {
    .name = "KQEMU",
    .cpu_interrupt = kqemu_cpu_interrupt,
@@ -1125,6 +1141,8 @@ QEMUAccel kqemu_accel = {
    .get_real_ticks = cpu_get_real_ticks,
 #endif
    .register_physical_memory = kqemu_set_phys_mem,
+    .trace_io = kqemu_trace_io,
+    .break_loop = kqemu_break_loop,
 };
 
 #endif
softmmu_template.h +4 -6
index 98dd378..4945352 100644
@@ -47,6 +47,8 @@
 #define ADDR_READ addr_read
 #endif
 
+#include "accel.h"
+
 static DATA_TYPE glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(target_ulong addr,
                                                        int mmu_idx,
                                                        void *retaddr);
@@ -75,9 +77,7 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(target_phys_addr_t physaddr,
    res |= (uint64_t)io_mem_read[index][2](io_mem_opaque[index], physaddr + 4) << 32;
 #endif
 #endif /* SHIFT > 2 */
-#ifdef USE_KQEMU
-    env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
    return res;
 }
 
@@ -220,9 +220,7 @@ static inline void glue(io_write, SUFFIX)(target_phys_addr_t physaddr,
    io_mem_write[index][2](io_mem_opaque[index], physaddr + 4, val >> 32);
 #endif
 #endif /* SHIFT > 2 */
-#ifdef USE_KQEMU
-    env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
 }
 
 void REGPARM glue(glue(__st, SUFFIX), MMUSUFFIX)(target_ulong addr,
vl.c +5 -20
index 964205d..e64becb 100644
@@ -420,10 +420,7 @@ void cpu_outb(CPUState *env, int addr, int val)
        fprintf(logfile, "outb: %04x %02x\n", addr, val);
 #endif
    ioport_write(0, addr, val);
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
 }
 
 void cpu_outw(CPUState *env, int addr, int val)
@@ -433,10 +430,7 @@ void cpu_outw(CPUState *env, int addr, int val)
        fprintf(logfile, "outw: %04x %04x\n", addr, val);
 #endif
    ioport_write(1, addr, val);
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
 }
 
 void cpu_outl(CPUState *env, int addr, int val)
@@ -446,10 +440,7 @@ void cpu_outl(CPUState *env, int addr, int val)
        fprintf(logfile, "outl: %04x %08x\n", addr, val);
 #endif
    ioport_write(2, addr, val);
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
 }
 
 int cpu_inb(CPUState *env, int addr)
@@ -460,10 +451,7 @@ int cpu_inb(CPUState *env, int addr)
    if (loglevel & CPU_LOG_IOPORT)
        fprintf(logfile, "inb : %04x %02x\n", addr, val);
 #endif
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
    return val;
 }
 
@@ -475,10 +463,7 @@ int cpu_inw(CPUState *env, int addr)
    if (loglevel & CPU_LOG_IOPORT)
        fprintf(logfile, "inw : %04x %04x\n", addr, val);
 #endif
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
    return val;
 }
 

vl.c int cpu_inl(CPUState *env, int addr) · line 478

Quoted 8 lines
vl.c +1 -4
@@ -490,10 +475,7 @@ int cpu_inl(CPUState *env, int addr)
    if (loglevel & CPU_LOG_IOPORT)
        fprintf(logfile, "inl : %04x %08x\n", addr, val);
 #endif
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);

It would be great if all the new checks on the critical paths could remain wrapped in some kind of #ifdef for archs that don't have any acceleration implemented (also in other patches in this series).

[skipped a rant about the explosion of correctness fixes and clean-up and some guests in practice booting nearly 2x slower compared to a last year's qemu snapshot]

Regards

#51 lore raw

Re: [Qemu-devel] [PATCH 20/32] accel_trace_io

Quoted 219 lines · andrzej zaborowski

2008/10/23 Glauber Costa <[email protected]>:

Quoted 218 lines

From: Glauber Costa <[email protected]>

kqemu keeps trace of the last io done. Do it through an accel_wrapper.

---
 accel.c            |    2 ++
 accel.h            |   13 ++++++++++++-
 cpu-exec.c         |    9 ++-------
 kqemu.c            |   18 ++++++++++++++++++
 softmmu_template.h |   10 ++++------
 vl.c               |   30 ++++++------------------------
 6 files changed, 44 insertions(+), 38 deletions(-)
accel.c +2 -0
index bf1194d..0890039 100644
@@ -32,5 +32,7 @@ QEMUAccel noaccel = {
    .get_real_ticks = cpu_get_ticks,
 #endif
    .register_physical_memory = accel_nop,
+    .trace_io = accel_nop,
+    .break_loop = accel_nop,
 };
 
accel.h +12 -1
index dbb6372..b37175b 100644
@@ -19,7 +19,8 @@ typedef struct QEMUAccel {
 #endif
    void (*register_physical_memory)(uint64_t start_addr,
                                     ram_addr_t size, ram_addr_t phys_offset);
-
+    void (*trace_io)(CPUState *env);
+    int (*break_loop)(CPUState *env);
 } QEMUAccel;
 
 typedef struct QEMUCont {
@@ -142,4 +143,14 @@ static inline void accel_register_phys_mem(uint64_t start_addr,
 {
    current_accel->register_physical_memory(start_addr, size, phys_offset);
 }
+
+static inline void accel_trace_io(CPUState *env)
+{
+    current_accel->trace_io(env);
+}
+
+static inline int accel_break_loop(CPUState *env)
+{
+    return current_accel->break_loop(env);
+}
 #endif
cpu-exec.c +2 -7
index 88b7d6f..18908d5 100644
@@ -36,6 +36,7 @@
 #include <signal.h>
 #include <sys/ucontext.h>
 #endif
+#include "accel.h"
 
 #if defined(__sparc__) && !defined(HOST_SOLARIS)
 // Work around ugly bugs in glibc that mangle global register contents
@@ -646,13 +647,7 @@ int cpu_exec(CPUState *env1)
                }
                /* reset soft MMU for next block (it can currently
                   only be set by a memory fault) */
-#if defined(USE_KQEMU)
-#define MIN_CYCLE_BEFORE_SWITCH (100 * 1000)
-                if (kqemu_is_ok(env) &&
-                    (cpu_get_time_fast() - env->last_io_time) >= MIN_CYCLE_BEFORE_SWITCH) {
-                    cpu_loop_exit();
-                }
-#endif
+                accel_break_loop(env);
            } /* for(;;) */
        } else {
            env_to_regs();
kqemu.c +18 -0
index f4d905a..d38d0e3 100644
@@ -1107,6 +1107,22 @@ static int kqemu_profile(CPUState *env, char *buf)
    return len;
 }
 
+static void kqemu_trace_io(CPUState *env)
+{
+    if (env)
+        env->last_io_time = cpu_get_time_fast();
+}
+
+static int kqemu_break_loop(CPUState *env)
+{
+#define MIN_CYCLE_BEFORE_SWITCH (100 * 1000)
+    if (kqemu_is_ok(env) &&
+        (cpu_get_time_fast() - env->last_io_time) >= MIN_CYCLE_BEFORE_SWITCH) {
+        return 1;
+    }
+    return 0;
+}
+
 QEMUAccel kqemu_accel = {
    .name = "KQEMU",
    .cpu_interrupt = kqemu_cpu_interrupt,
@@ -1125,6 +1141,8 @@ QEMUAccel kqemu_accel = {
    .get_real_ticks = cpu_get_real_ticks,
 #endif
    .register_physical_memory = kqemu_set_phys_mem,
+    .trace_io = kqemu_trace_io,
+    .break_loop = kqemu_break_loop,
 };
 
 #endif
softmmu_template.h +4 -6
index 98dd378..4945352 100644
@@ -47,6 +47,8 @@
 #define ADDR_READ addr_read
 #endif
 
+#include "accel.h"
+
 static DATA_TYPE glue(glue(slow_ld, SUFFIX), MMUSUFFIX)(target_ulong addr,
                                                        int mmu_idx,
                                                        void *retaddr);
@@ -75,9 +77,7 @@ static inline DATA_TYPE glue(io_read, SUFFIX)(target_phys_addr_t physaddr,
    res |= (uint64_t)io_mem_read[index][2](io_mem_opaque[index], physaddr + 4) << 32;
 #endif
 #endif /* SHIFT > 2 */
-#ifdef USE_KQEMU
-    env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
    return res;
 }
 
@@ -220,9 +220,7 @@ static inline void glue(io_write, SUFFIX)(target_phys_addr_t physaddr,
    io_mem_write[index][2](io_mem_opaque[index], physaddr + 4, val >> 32);
 #endif
 #endif /* SHIFT > 2 */
-#ifdef USE_KQEMU
-    env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
 }
 
 void REGPARM glue(glue(__st, SUFFIX), MMUSUFFIX)(target_ulong addr,
vl.c +5 -20
index 964205d..e64becb 100644
@@ -420,10 +420,7 @@ void cpu_outb(CPUState *env, int addr, int val)
        fprintf(logfile, "outb: %04x %02x\n", addr, val);
 #endif
    ioport_write(0, addr, val);
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
 }
 
 void cpu_outw(CPUState *env, int addr, int val)
@@ -433,10 +430,7 @@ void cpu_outw(CPUState *env, int addr, int val)
        fprintf(logfile, "outw: %04x %04x\n", addr, val);
 #endif
    ioport_write(1, addr, val);
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
 }
 
 void cpu_outl(CPUState *env, int addr, int val)
@@ -446,10 +440,7 @@ void cpu_outl(CPUState *env, int addr, int val)
        fprintf(logfile, "outl: %04x %08x\n", addr, val);
 #endif
    ioport_write(2, addr, val);
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
 }
 
 int cpu_inb(CPUState *env, int addr)
@@ -460,10 +451,7 @@ int cpu_inb(CPUState *env, int addr)
    if (loglevel & CPU_LOG_IOPORT)
        fprintf(logfile, "inb : %04x %02x\n", addr, val);
 #endif
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
    return val;
 }
 
@@ -475,10 +463,7 @@ int cpu_inw(CPUState *env, int addr)
    if (loglevel & CPU_LOG_IOPORT)
        fprintf(logfile, "inw : %04x %04x\n", addr, val);
 #endif
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);
    return val;
 }
 
Quoted 13 lines

vl.c int cpu_inl(CPUState *env, int addr) · line 478

Quoted 9 lines
vl.c +1 -4
@@ -490,10 +475,7 @@ int cpu_inl(CPUState *env, int addr)
    if (loglevel & CPU_LOG_IOPORT)
        fprintf(logfile, "inl : %04x %08x\n", addr, val);
 #endif
-#ifdef USE_KQEMU
-    if (env)
-        env->last_io_time = cpu_get_time_fast();
-#endif
+    accel_trace_io(env);

It would be great if all the new checks on the critical paths could remain wrapped in some kind of #ifdef for archs that don't have any acceleration implemented (also in other patches in this series).

Yeah, me and anthony were discussing exactly that, yesterday. It's part of the plan now.

Signature · 5 lines
Glauber  Costa.
"Free as in Freedom"
http://glommer.net

"The less confident you are, the more serious you have to act."
#52 lore raw

PATCH 21/32 get_env accel wrapper

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

Allow the current accelerator to provide it's own, customized address of the CPUState structure used for the env variable.

---
 accel.c              |    6 ++++++
 accel.h              |    8 ++++++++
 kqemu.c              |   12 ++++++++++--
 kqemu.h              |   10 ++++++++++
 target-i386/cpu.h    |    1 -
 target-i386/helper.c |    2 +-
 6 files changed, 35 insertions(+), 4 deletions(-)
accel.c +6 -0
index 0890039..28dd2ee 100644
@@ -14,6 +14,11 @@ int noaccel_info(CPUState *env, char *buf)
     return snprintf(buf, MAX_INFO_BUF, "no accelerator present.\n");
 }
 
+CPUState *noaccel_get_env(void)
+{
+    return qemu_mallocz(sizeof(CPUState));
+}
+
 #define accel_nop ((void *)_accel_nop)
 
 /* Accelerator wrapper for the no-accel (raw qemu) case */
@@ -21,6 +26,7 @@ QEMUAccel noaccel = {
     .name = "none",
     .cpu_interrupt = accel_nop,
     .init_env = accel_nop,
+    .get_env = noaccel_get_env,
     .start = accel_nop,
     .flush_cache = accel_nop,
     .flush_page = accel_nop,
accel.h +8 -0
index b37175b..0c5ff33 100644
@@ -6,6 +6,7 @@
 typedef struct QEMUAccel {
     char *name;
     void (*cpu_interrupt)(CPUState *env);
+    CPUState *(*get_env)(void);
     void (*init_env)(CPUState *env);
     int (*start)(int cpus);
     void (*flush_cache)(CPUState *env, int global);
@@ -33,10 +34,12 @@ extern QEMUAccel *current_accel;
 extern QEMUAccel noaccel;
 #ifdef USE_KQEMU
 extern QEMUAccel kqemu_accel;
+extern QEMUAccel kqemu_kernel_accel;
 #endif
 
 extern QEMUCont *head;
 void *qemu_mallocz(size_t size);
+extern CPUState *noaccel_get_env(void);
 
 static inline int register_qemu_accel(QEMUAccel *accel)
 {
@@ -93,6 +96,11 @@ static inline int accel_start(int cpus)
     return status;
 }
 
+static inline CPUState *accel_get_env(void)
+{
+    return current_accel->get_env();
+}
+
 static inline void accel_init_env(CPUState *env)
 {
     current_accel->init_env(env);
kqemu.c +10 -2
index d38d0e3..5ca0f76 100644
@@ -1110,23 +1110,31 @@ static int kqemu_profile(CPUState *env, char *buf)
 static void kqemu_trace_io(CPUState *env)
 {
     if (env)
-        env->last_io_time = cpu_get_time_fast();
+        kqemu_cpu_field(env,last_io_time) = cpu_get_time_fast();
 }
 
 static int kqemu_break_loop(CPUState *env)
 {
 #define MIN_CYCLE_BEFORE_SWITCH (100 * 1000)
     if (kqemu_is_ok(env) &&
-        (cpu_get_time_fast() - env->last_io_time) >= MIN_CYCLE_BEFORE_SWITCH) {
+        (cpu_get_time_fast() - kqemu_cpu_field(env,last_io_time)) >= MIN_CYCLE_BEFORE_SWITCH) {
         return 1;
     }
     return 0;
 }
 
+static CPUState *kqemu_get_env(void)
+{
+    KQEMUCPUState *kenv;
+    kenv = qemu_mallocz(sizeof(KQEMUCPUState));
+    return &kenv->env;
+}
+
 QEMUAccel kqemu_accel = {
     .name = "KQEMU",
     .cpu_interrupt = kqemu_cpu_interrupt,
     .init_env = kqemu_init_env,
+    .get_env = kqemu_get_env,
     .start = kqemu_start,
     .flush_cache = kqemu_flush,
     .flush_page = kqemu_flush_page,
kqemu.h +10 -0
index 1c7e024..cf14179 100644
@@ -157,4 +157,14 @@ struct kqemu_phys_mem {
 #define KQEMU_SET_PHYS_MEM     _IOW('q', 5, struct kqemu_phys_mem)
 #endif
 
+typedef struct KQEMUCPUstate {
+    int kqemu_enabled;
+    int last_io_time;
+    CPUState env;
+} KQEMUCPUState;
+
+#define kqemu_cpu_field(env, field) (*({ \
+    KQEMUCPUState *__c = container_of(env, KQEMUCPUState, env); \
+    &__c->field; }))
+
 #endif /* KQEMU_H */
target-i386/cpu.h +0 -1
index 3c11e0f..8a2d797 100644
@@ -608,7 +608,6 @@ typedef struct CPUX86State {
 
 #ifdef USE_KQEMU
     int kqemu_enabled;
-    int last_io_time;
 #endif
     /* in order to simplify APIC support, we leave this pointer to the
        user */
target-i386/helper.c +1 -1
index b981b92..5ff051f 100644
@@ -98,7 +98,7 @@ CPUX86State *cpu_x86_init(const char *cpu_model)
     CPUX86State *env;
     static int inited;
 
-    env = qemu_mallocz(sizeof(CPUX86State));
+    env = accel_get_env();
     if (!env)
         return NULL;
     cpu_exec_init(env);
Signature · 1 line
1.5.5.1
#53 lore raw

[Qemu-devel] Re: [PATCH 21/32] get_env accel wrapper

accel.c QEMUAccel noaccel = { · line 30

Quoted 12 lines · Glauber Costa

From: Glauber Costa <[email protected]>

Allow the current accelerator to provide it's own, customized address of the CPUState structure used for the env variable.

/* Accelerator wrapper for the no-accel (raw qemu) case */

accel.c +1 -0
@@ -21,6 +26,7 @@ QEMUAccel noaccel = {
     .name = "none",
     .cpu_interrupt = accel_nop,
     .init_env = accel_nop,
+    .get_env = noaccel_get_env,
 

.create_env() ?

kqemu.h struct kqemu_phys_mem { · line 163

Quoted 6 lines
kqemu.h +4 -0
+typedef struct KQEMUCPUstate {
+    int kqemu_enabled;
+    int last_io_time;
+    CPUState env;

Tradition is to put it as the first member.

kqemu.h struct kqemu_phys_mem { · line 168

Quoted 6 lines
kqemu.h +5 -0
+} KQEMUCPUState;
+
+#define kqemu_cpu_field(env, field) (*({ \
+    KQEMUCPUState *__c = container_of(env, KQEMUCPUState, env); \
+    &__c->field; }))

This is evil. The resulting code is less readable.

I'd prefer a KQEMUCPUState *kqemu_state(CPUState *env) { ... } even though it means one more line of code per usage.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#54 lore raw

PATCH 22/32 add next_cpu_index

In reply to Glauber Costa

From: Glauber Costa <[email protected]>

separate the logic for calculating the next cpu index from cpu creation. It will allow others to query what's the next cpu index to be created before cpu creation.

---
 exec.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
exec.c +14 -8
index 80b8a78..7fe7eeb 100644
@@ -526,25 +526,31 @@ static int cpu_common_load(QEMUFile *f, void *opaque, int version_id)
 }
 #endif
 
-void cpu_exec_init(CPUState *env)
+int next_cpu_index(void)
 {
     CPUState **penv;
-    int cpu_index;
+    int cpu_index = 0;
 
-    env->next_cpu = NULL;
     penv = &first_cpu;
-    cpu_index = 0;
+
     while (*penv != NULL) {
         penv = (CPUState **)&(*penv)->next_cpu;
         cpu_index++;
     }
-    env->cpu_index = cpu_index;
+    return cpu_index;
+}
+
+void cpu_exec_init(CPUState *env)
+{
+    env->next_cpu = NULL;
+    env->cpu_index = next_cpu_index();
     env->nb_watchpoints = 0;
-    *penv = env;
+    if (env->cpu_index == 0)
+        first_cpu = env;
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
-    register_savevm("cpu_common", cpu_index, CPU_COMMON_SAVE_VERSION,
+    register_savevm("cpu_common", env->cpu_index, CPU_COMMON_SAVE_VERSION,
                     cpu_common_save, cpu_common_load, env);
-    register_savevm("cpu", cpu_index, CPU_SAVE_VERSION,
+    register_savevm("cpu", env->cpu_index, CPU_SAVE_VERSION,
                     cpu_save, cpu_load, env);
 #endif
 }
Signature · 1 line
1.5.5.1
#55 lore raw

[Qemu-devel] Re: [PATCH 22/32] add next_cpu_index

Quoted 6 lines · Glauber Costa

From: Glauber Costa <[email protected]>

separate the logic for calculating the next cpu index from cpu creation. It will allow others to query what's the next cpu index to be created before cpu creation.

What is this useful for?

Regards,

Anthony Liguori

Quoted 50 lines
---
 exec.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
exec.c +14 -8
index 80b8a78..7fe7eeb 100644
@@ -526,25 +526,31 @@ static int cpu_common_load(QEMUFile *f, void *opaque, int version_id)
 }
 #endif
 
-void cpu_exec_init(CPUState *env)
+int next_cpu_index(void)
 {
     CPUState **penv;
-    int cpu_index;
+    int cpu_index = 0;
 
-    env->next_cpu = NULL;
     penv = &first_cpu;
-    cpu_index = 0;
+
     while (*penv != NULL) {
         penv = (CPUState **)&(*penv)->next_cpu;
         cpu_index++;
     }
-    env->cpu_index = cpu_index;
+    return cpu_index;
+}
+
+void cpu_exec_init(CPUState *env)
+{
+    env->next_cpu = NULL;
+    env->cpu_index = next_cpu_index();
     env->nb_watchpoints = 0;
-    *penv = env;
+    if (env->cpu_index == 0)
+        first_cpu = env;
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
-    register_savevm("cpu_common", cpu_index, CPU_COMMON_SAVE_VERSION,
+    register_savevm("cpu_common", env->cpu_index, CPU_COMMON_SAVE_VERSION,
                     cpu_common_save, cpu_common_load, env);
-    register_savevm("cpu", cpu_index, CPU_SAVE_VERSION,
+    register_savevm("cpu", env->cpu_index, CPU_SAVE_VERSION,
                     cpu_save, cpu_load, env);
 #endif
 }
#56 lore raw

[Qemu-devel] Re: [PATCH 22/32] add next_cpu_index

Quoted 9 lines · Anthony Liguori
Quoted 6 lines · Glauber Costa

From: Glauber Costa <[email protected]>

separate the logic for calculating the next cpu index from cpu creation. It will allow others to query what's the next cpu index to be created before cpu creation.

What is this useful for?

In earlier versions of the series, I was passing the cpu_index to init_env. So I guess it's just a die hard patch that survived the reworks. It can be dropped now (although I believe its clearer this way).

Quoted 56 lines

Regards,

Anthony Liguori

Quoted 50 lines
---
 exec.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
exec.c +14 -8
index 80b8a78..7fe7eeb 100644
@@ -526,25 +526,31 @@ static int cpu_common_load(QEMUFile *f, void *opaque, int version_id)
 }
 #endif
 
-void cpu_exec_init(CPUState *env)
+int next_cpu_index(void)
 {
     CPUState **penv;
-    int cpu_index;
+    int cpu_index = 0;
 
-    env->next_cpu = NULL;
     penv = &first_cpu;
-    cpu_index = 0;
+
     while (*penv != NULL) {
         penv = (CPUState **)&(*penv)->next_cpu;
         cpu_index++;
     }
-    env->cpu_index = cpu_index;
+    return cpu_index;
+}
+
+void cpu_exec_init(CPUState *env)
+{
+    env->next_cpu = NULL;
+    env->cpu_index = next_cpu_index();
     env->nb_watchpoints = 0;
-    *penv = env;
+    if (env->cpu_index == 0)
+        first_cpu = env;
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
-    register_savevm("cpu_common", cpu_index, CPU_COMMON_SAVE_VERSION,
+    register_savevm("cpu_common", env->cpu_index, CPU_COMMON_SAVE_VERSION,
                     cpu_common_save, cpu_common_load, env);
-    register_savevm("cpu", cpu_index, CPU_SAVE_VERSION,
+    register_savevm("cpu", env->cpu_index, CPU_SAVE_VERSION,
                     cpu_save, cpu_load, env);
 #endif
 }
#57 lore raw

[Qemu-devel] Re: [PATCH 22/32] add next_cpu_index

Quoted 4 lines · Glauber Costa
Quoted 3 lines · Anthony Liguori
Quoted 2 lines · Glauber Costa

From: Glauber Costa <[email protected]>

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines

separate the logic for calculating the next cpu index from cpu creation. It will allow others to query what's the next cpu index to be created before cpu creation.

What is this useful for?

In earlier versions of the series, I was passing the cpu_index to init_env. So I guess it's just a die hard patch that survived the reworks. It can be dropped now (although I believe its clearer this way).

Why not keep track of the last assigned cpu_index in a global or static variable? That should be clearer and avoids the iteration (which is basically a count-how-many-cpus-we-already-have loop).

Jan

Quoted 55 lines
Quoted 55 lines

Regards,

Anthony Liguori

Quoted 50 lines
---
 exec.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
exec.c +14 -8
index 80b8a78..7fe7eeb 100644
@@ -526,25 +526,31 @@ static int cpu_common_load(QEMUFile *f, void *opaque, int version_id)
 }
 #endif
 
-void cpu_exec_init(CPUState *env)
+int next_cpu_index(void)
 {
     CPUState **penv;
-    int cpu_index;
+    int cpu_index = 0;
 
-    env->next_cpu = NULL;
     penv = &first_cpu;
-    cpu_index = 0;
+
     while (*penv != NULL) {
         penv = (CPUState **)&(*penv)->next_cpu;
         cpu_index++;
     }
-    env->cpu_index = cpu_index;
+    return cpu_index;
+}
+
+void cpu_exec_init(CPUState *env)
+{
+    env->next_cpu = NULL;
+    env->cpu_index = next_cpu_index();
     env->nb_watchpoints = 0;
-    *penv = env;
+    if (env->cpu_index == 0)
+        first_cpu = env;
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
-    register_savevm("cpu_common", cpu_index, CPU_COMMON_SAVE_VERSION,
+    register_savevm("cpu_common", env->cpu_index, CPU_COMMON_SAVE_VERSION,
                     cpu_common_save, cpu_common_load, env);
-    register_savevm("cpu", cpu_index, CPU_SAVE_VERSION,
+    register_savevm("cpu", env->cpu_index, CPU_SAVE_VERSION,
                     cpu_save, cpu_load, env);
 #endif
 }
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#58 lore raw

[Qemu-devel] Re: [PATCH 22/32] add next_cpu_index

Quoted 9 lines · Jan Kiszka
Quoted 8 lines · Glauber Costa
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Glauber Costa

From: Glauber Costa <[email protected]>

separate the logic for calculating the next cpu index from cpu creation. It will allow others to query what's the next cpu index to be created before cpu creation.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

What is this useful for?

In earlier versions of the series, I was passing the cpu_index to init_env. So I guess it's just a die hard patch that survived the reworks. It can be dropped now (although I believe its clearer this way).

Why not keep track of the last assigned cpu_index in a global or static variable? That should be clearer and avoids the iteration (which is basically a count-how-many-cpus-we-already-have loop).

I like this. A "next_cpu_index()" function that increments it atomically would do just fine. We don't have this kind of race yet for lack of smpbility, but it's one less thing to fix in the future.

Quoted 63 lines

Jan

Quoted 55 lines
Quoted 55 lines

Regards,

Anthony Liguori

Quoted 50 lines
---
 exec.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
exec.c +14 -8
index 80b8a78..7fe7eeb 100644
@@ -526,25 +526,31 @@ static int cpu_common_load(QEMUFile *f, void *opaque, int version_id)
 }
 #endif
 
-void cpu_exec_init(CPUState *env)
+int next_cpu_index(void)
 {
     CPUState **penv;
-    int cpu_index;
+    int cpu_index = 0;
 
-    env->next_cpu = NULL;
     penv = &first_cpu;
-    cpu_index = 0;
+
     while (*penv != NULL) {
         penv = (CPUState **)&(*penv)->next_cpu;
         cpu_index++;
     }
-    env->cpu_index = cpu_index;
+    return cpu_index;
+}
+
+void cpu_exec_init(CPUState *env)
+{
+    env->next_cpu = NULL;
+    env->cpu_index = next_cpu_index();
     env->nb_watchpoints = 0;
-    *penv = env;
+    if (env->cpu_index == 0)
+        first_cpu = env;
 #if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
-    register_savevm("cpu_common", cpu_index, CPU_COMMON_SAVE_VERSION,
+    register_savevm("cpu_common", env->cpu_index, CPU_COMMON_SAVE_VERSION,
                     cpu_common_save, cpu_common_load, env);
-    register_savevm("cpu", cpu_index, CPU_SAVE_VERSION,
+    register_savevm("cpu", env->cpu_index, CPU_SAVE_VERSION,
                     cpu_save, cpu_load, env);
 #endif
 }
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#59 lore raw

PATCH 23/32 move cpu_get_time_fast to kqemu.c

In reply to Glauber Costa

remove it from generic code

---
 kqemu.c           |    7 +++++++
 target-i386/cpu.h |    9 ---------
 2 files changed, 7 insertions(+), 9 deletions(-)
kqemu.c +7 -0
index 5ca0f76..16ebe7d 100644
@@ -90,6 +90,13 @@ uint8_t *modified_ram_pages_table;
 int qpi_io_memory;
 uint32_t kqemu_comm_base; /* physical address of the QPI communication page */
 
+static inline int cpu_get_time_fast(void)
+{
+    int low, high;
+    asm volatile("rdtsc" : "=a" (low), "=d" (high));
+    return low;
+}
+
 #define cpuid(index, eax, ebx, ecx, edx) \
   asm volatile ("cpuid" \
                 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) \
target-i386/cpu.h +0 -9
index 8a2d797..6310529 100644
@@ -726,15 +726,6 @@ void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0);
 #define X86_DUMP_FPU  0x0001 /* dump FPU state too */
 #define X86_DUMP_CCOP 0x0002 /* dump qemu flag cache */
 
-#ifdef USE_KQEMU
-static inline int cpu_get_time_fast(void)
-{
-    int low, high;
-    asm volatile("rdtsc" : "=a" (low), "=d" (high));
-    return low;
-}
-#endif
-
 #define TARGET_PAGE_BITS 12
 
 #define CPUState CPUX86State
Signature · 1 line
1.5.5.1
#60 lore raw

PATCH 24/32 check wether kqemu is enabled in open code

In reply to Glauber Costa

kqemu is still too much spread around. The proper fix usually involves rethinking a bit of kqemu logic so for now, just check whether or not kqemu is enabled. If the kqemu accelerator is not present, consider it not. Otherwise, check env field.

---
 cpu-exec.c |    2 +-
 kqemu.c    |   21 +++++++++++++++++++++
 kqemu.h    |    3 +++
 3 files changed, 25 insertions(+), 1 deletions(-)
cpu-exec.c +1 -1
index 18908d5..b47cf43 100644
@@ -599,7 +599,7 @@ int cpu_exec(CPUState *env1)
                 {
                     if (next_tb != 0 &&
 #ifdef USE_KQEMU
-                        (env->kqemu_enabled != 2) &&
+                        (!kqemu_kernel_enabled(env)) &&
 #endif
                         tb->page_addr[1] == -1) {
                     tb_add_jump((TranslationBlock *)(next_tb & ~3), next_tb & 3, tb);
kqemu.c +21 -0
index 16ebe7d..f99a4f1 100644
@@ -126,6 +126,27 @@ static int is_cpuid_supported(void)
 }
 #endif
 
+/* FIXME: Should not be needed, since ideally, QEMUAccel would avoid all kqemu tests
+ * altogether
+ */
+int kqemu_is_enabled(CPUState *env)
+{
+    if (strcasecmp(current_accel->name, "kqemu")) {
+        return 0;
+    }
+
+    return env->kqemu_enabled;
+
+}
+
+int kqemu_kernel_enabled(CPUState *env)
+{
+    if (strcasecmp(current_accel->name, "kqemu")) {
+        return 0;
+    }
+    return env->kqemu_enabled == 2;
+}
+
 static void kqemu_update_cpuid(CPUState *env)
 {
     int critical_features_mask, features, ext_features, ext_features_mask;
kqemu.h +3 -0
index cf14179..62ba1d9 100644
@@ -157,6 +157,9 @@ struct kqemu_phys_mem {
 #define KQEMU_SET_PHYS_MEM     _IOW('q', 5, struct kqemu_phys_mem)
 #endif
 
+int kqemu_is_enabled(CPUState *env);
+int kqemu_kernel_enabled(CPUState *env);
+
 typedef struct KQEMUCPUstate {
     int kqemu_enabled;
     int last_io_time;
Signature · 1 line
1.5.5.1
#61 lore raw

[Qemu-devel] Re: [PATCH 24/32] check wether kqemu is enabled in open code

Quoted 17 lines · Glauber Costa

kqemu is still too much spread around. The proper fix usually involves rethinking a bit of kqemu logic so for now, just check whether or not kqemu is enabled. If the kqemu accelerator is not present, consider it not. Otherwise, check env field.

---
 cpu-exec.c |    2 +-
 kqemu.c    |   21 +++++++++++++++++++++
 kqemu.h    |    3 +++
 3 files changed, 25 insertions(+), 1 deletions(-)
cpu-exec.c +0 -0
index 18908d5..b47cf43 100644

cpu-exec.c int cpu_exec(CPUState *env1) · line 603

Quoted 6 lines
cpu-exec.c +1 -1
@@ -599,7 +599,7 @@ int cpu_exec(CPUState *env1)
                 {
                     if (next_tb != 0 &&
 #ifdef USE_KQEMU
-                        (env->kqemu_enabled != 2) &&
+                        (!kqemu_kernel_enabled(env)) &&
 #endif

If this ifdef is still here to foster rethinking of the check - OK :). Otherwise I would suggest to wrap kqemu_kernel_enabled for the !USE_KQEMU case.

Quoted 39 lines
cpu-exec.c +0 -0
                         tb->page_addr[1] == -1) {
                     tb_add_jump((TranslationBlock *)(next_tb & ~3), next_tb & 3, tb);
kqemu.c +21 -0
index 16ebe7d..f99a4f1 100644
@@ -126,6 +126,27 @@ static int is_cpuid_supported(void)
 }
 #endif
 
+/* FIXME: Should not be needed, since ideally, QEMUAccel would avoid all kqemu tests
+ * altogether
+ */
+int kqemu_is_enabled(CPUState *env)
+{
+    if (strcasecmp(current_accel->name, "kqemu")) {
+        return 0;
+    }
+
+    return env->kqemu_enabled;
+
+}
+
+int kqemu_kernel_enabled(CPUState *env)
+{
+    if (strcasecmp(current_accel->name, "kqemu")) {
+        return 0;
+    }
+    return env->kqemu_enabled == 2;
+}
+
 static void kqemu_update_cpuid(CPUState *env)
 {
     int critical_features_mask, features, ext_features, ext_features_mask;
kqemu.h +0 -0
index cf14179..62ba1d9 100644

kqemu.h struct kqemu_phys_mem { · line 165

Quoted 9 lines
kqemu.h +3 -0
@@ -157,6 +157,9 @@ struct kqemu_phys_mem {
 #define KQEMU_SET_PHYS_MEM     _IOW('q', 5, struct kqemu_phys_mem)
 #endif
 
+int kqemu_is_enabled(CPUState *env);
+int kqemu_kernel_enabled(CPUState *env);
+
 typedef struct KQEMUCPUstate {
     int kqemu_enabled;
     int last_io_time;

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#62 lore raw

[Qemu-devel] Re: [PATCH 24/32] check wether kqemu is enabled in open code

Quoted 13 lines · Jan Kiszka
Quoted 12 lines · Glauber Costa

kqemu is still too much spread around. The proper fix usually involves rethinking a bit of kqemu logic so for now, just check whether or not kqemu is enabled. If the kqemu accelerator is not present, consider it not. Otherwise, check env field.

---
 cpu-exec.c |    2 +-
 kqemu.c    |   21 +++++++++++++++++++++
 kqemu.h    |    3 +++
 3 files changed, 25 insertions(+), 1 deletions(-)
Quoted 15 lines

cpu-exec.c int cpu_exec(CPUState *env1) · line 603

Quoted 11 lines
cpu-exec.c +1 -1
index 18908d5..b47cf43 100644
@@ -599,7 +599,7 @@ int cpu_exec(CPUState *env1)
                 {
                     if (next_tb != 0 &&
 #ifdef USE_KQEMU
-                        (env->kqemu_enabled != 2) &&
+                        (!kqemu_kernel_enabled(env)) &&
 #endif

If this ifdef is still here to foster rethinking of the check - OK :). Otherwise I would suggest to wrap kqemu_kernel_enabled for the !USE_KQEMU case.

Yes. Ideally, it should disappear, so I see no value of "solving" it.

Quoted 55 lines
Quoted 40 lines
cpu-exec.c +0 -0
                         tb->page_addr[1] == -1) {
                     tb_add_jump((TranslationBlock *)(next_tb & ~3), next_tb & 3, tb);
kqemu.c +21 -0
index 16ebe7d..f99a4f1 100644
@@ -126,6 +126,27 @@ static int is_cpuid_supported(void)
 }
 #endif
 
+/* FIXME: Should not be needed, since ideally, QEMUAccel would avoid all kqemu tests
+ * altogether
+ */
+int kqemu_is_enabled(CPUState *env)
+{
+    if (strcasecmp(current_accel->name, "kqemu")) {
+        return 0;
+    }
+
+    return env->kqemu_enabled;
+
+}
+
+int kqemu_kernel_enabled(CPUState *env)
+{
+    if (strcasecmp(current_accel->name, "kqemu")) {
+        return 0;
+    }
+    return env->kqemu_enabled == 2;
+}
+
 static void kqemu_update_cpuid(CPUState *env)
 {
     int critical_features_mask, features, ext_features, ext_features_mask;
kqemu.h +0 -0
index cf14179..62ba1d9 100644

kqemu.h struct kqemu_phys_mem { · line 165

Quoted 9 lines
kqemu.h +3 -0
@@ -157,6 +157,9 @@ struct kqemu_phys_mem {
 #define KQEMU_SET_PHYS_MEM     _IOW('q', 5, struct kqemu_phys_mem)
 #endif
 
+int kqemu_is_enabled(CPUState *env);
+int kqemu_kernel_enabled(CPUState *env);
+
 typedef struct KQEMUCPUstate {
     int kqemu_enabled;
     int last_io_time;

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#63 lore raw

[Qemu-devel] Re: [PATCH 24/32] check wether kqemu is enabled in open code

In reply to Glauber Costa
Quoted 44 lines · Glauber Costa

kqemu is still too much spread around. The proper fix usually involves rethinking a bit of kqemu logic so for now, just check whether or not kqemu is enabled. If the kqemu accelerator is not present, consider it not. Otherwise, check env field.

---
 cpu-exec.c |    2 +-
 kqemu.c    |   21 +++++++++++++++++++++
 kqemu.h    |    3 +++
 3 files changed, 25 insertions(+), 1 deletions(-)
cpu-exec.c +1 -1
index 18908d5..b47cf43 100644
@@ -599,7 +599,7 @@ int cpu_exec(CPUState *env1)
                 {
                     if (next_tb != 0 &&
 #ifdef USE_KQEMU
-                        (env->kqemu_enabled != 2) &&
+                        (!kqemu_kernel_enabled(env)) &&
 #endif
                         tb->page_addr[1] == -1) {
                     tb_add_jump((TranslationBlock *)(next_tb & ~3), next_tb & 3, tb);
kqemu.c +11 -0
index 16ebe7d..f99a4f1 100644
@@ -126,6 +126,27 @@ static int is_cpuid_supported(void)
 }
 #endif
 
+/* FIXME: Should not be needed, since ideally, QEMUAccel would avoid all kqemu tests
+ * altogether
+ */
+int kqemu_is_enabled(CPUState *env)
+{
+    if (strcasecmp(current_accel->name, "kqemu")) {
+        return 0;
+    }
+
+    return env->kqemu_enabled;
+

kqemu.c static int is_cpuid_supported(void) · line 149

Quoted 10 lines
kqemu.c +9 -0
+}
+
+int kqemu_kernel_enabled(CPUState *env)
+{
+    if (strcasecmp(current_accel->name, "kqemu")) {
+        return 0;
+    }
+    return env->kqemu_enabled == 2;
+}
 

Why is kqemu_enabled part of the vcpu state? Wouldn't it always be 0 even if we weren't using the accelerator?

Regards,

Anthony Liguori

Quoted 18 lines
kqemu.c +0 -0
 static void kqemu_update_cpuid(CPUState *env)
 {
     int critical_features_mask, features, ext_features, ext_features_mask;
kqemu.h +3 -0
index cf14179..62ba1d9 100644
@@ -157,6 +157,9 @@ struct kqemu_phys_mem {
 #define KQEMU_SET_PHYS_MEM     _IOW('q', 5, struct kqemu_phys_mem)
 #endif
 
+int kqemu_is_enabled(CPUState *env);
+int kqemu_kernel_enabled(CPUState *env);
+
 typedef struct KQEMUCPUstate {
     int kqemu_enabled;
     int last_io_time;
#64 lore raw

[Qemu-devel] Re: [PATCH 24/32] check wether kqemu is enabled in open code

Quoted 50 lines · Anthony Liguori
Quoted 49 lines · Glauber Costa

kqemu is still too much spread around. The proper fix usually involves rethinking a bit of kqemu logic so for now, just check whether or not kqemu is enabled. If the kqemu accelerator is not present, consider it not. Otherwise, check env field.

---
 cpu-exec.c |    2 +-
 kqemu.c    |   21 +++++++++++++++++++++
 kqemu.h    |    3 +++
 3 files changed, 25 insertions(+), 1 deletions(-)
cpu-exec.c +1 -1
index 18908d5..b47cf43 100644
@@ -599,7 +599,7 @@ int cpu_exec(CPUState *env1)
                 {
                     if (next_tb != 0 &&
 #ifdef USE_KQEMU
-                        (env->kqemu_enabled != 2) &&
+                        (!kqemu_kernel_enabled(env)) &&
 #endif
                         tb->page_addr[1] == -1) {
                     tb_add_jump((TranslationBlock *)(next_tb & ~3), next_tb & 3, tb);
kqemu.c +16 -0
index 16ebe7d..f99a4f1 100644
@@ -126,6 +126,27 @@ static int is_cpuid_supported(void)
 }
 #endif
 
+/* FIXME: Should not be needed, since ideally, QEMUAccel would avoid all kqemu tests
+ * altogether
+ */
+int kqemu_is_enabled(CPUState *env)
+{
+    if (strcasecmp(current_accel->name, "kqemu")) {
+        return 0;
+    }
+
+    return env->kqemu_enabled;
+
+}
+
+int kqemu_kernel_enabled(CPUState *env)
+{
+    if (strcasecmp(current_accel->name, "kqemu")) {
Quoted 8 lines

kqemu.c static int is_cpuid_supported(void)

Quoted 5 lines
kqemu.c +4 -0
+        return 0;
+    }
+    return env->kqemu_enabled == 2;
+}
 

Why is kqemu_enabled part of the vcpu state? Wouldn't it always be 0 even if we weren't using the accelerator?

It's temporary, to keep things compiling/working. It's dropped in a later patch.

Quoted 24 lines

Regards,

Anthony Liguori

Quoted 18 lines
kqemu.c +0 -0
 static void kqemu_update_cpuid(CPUState *env)
 {
     int critical_features_mask, features, ext_features, ext_features_mask;
kqemu.h +3 -0
index cf14179..62ba1d9 100644
@@ -157,6 +157,9 @@ struct kqemu_phys_mem {
 #define KQEMU_SET_PHYS_MEM     _IOW('q', 5, struct kqemu_phys_mem)
 #endif
 
+int kqemu_is_enabled(CPUState *env);
+int kqemu_kernel_enabled(CPUState *env);
+
 typedef struct KQEMUCPUstate {
     int kqemu_enabled;
     int last_io_time;
#65 lore raw

PATCH 25/32 provide accel hook for cpu_exec

In reply to Glauber Costa

let kqemu_cpu_exec be called through an accelerator hook. Some parts of what was done in cpu_execution cannot go to a separate functions, because of code generator constraints:
compute_all() is an example, because the function definition will get no parameters and yet expect env to be at AREG0. This expects a particular frame that is destroyed by function calls.

---
 accel.c    |    7 +++++++
 accel.h    |    6 ++++++
 cpu-exec.c |    5 ++---
 exec-all.h |    1 -
 kqemu.c    |    5 +++--
 5 files changed, 18 insertions(+), 6 deletions(-)
accel.c +7 -0
index 28dd2ee..8d635f0 100644
@@ -1,4 +1,5 @@
 #include "hw/hw.h"
+#include "exec-all.h"
 #include "accel.h"
 
 QEMUAccel *current_accel;
@@ -19,6 +20,11 @@ CPUState *noaccel_get_env(void)
     return qemu_mallocz(sizeof(CPUState));
 }
 
+int noaccel_cpu_exec(CPUState *env)
+{
+    return EXEC_EXIT_SOFTMMU;
+}
+
 #define accel_nop ((void *)_accel_nop)
 
 /* Accelerator wrapper for the no-accel (raw qemu) case */
@@ -40,5 +46,6 @@ QEMUAccel noaccel = {
     .register_physical_memory = accel_nop,
     .trace_io = accel_nop,
     .break_loop = accel_nop,
+    .cpu_exec = noaccel_cpu_exec,
 };
 
accel.h +6 -0
index 0c5ff33..1741f06 100644
@@ -22,6 +22,7 @@ typedef struct QEMUAccel {
                                      ram_addr_t size, ram_addr_t phys_offset);
     void (*trace_io)(CPUState *env);
     int (*break_loop)(CPUState *env);
+    int (*cpu_exec)(CPUState *env);
 } QEMUAccel;
 
 typedef struct QEMUCont {
@@ -161,4 +162,9 @@ static inline int accel_break_loop(CPUState *env)
 {
     return current_accel->break_loop(env);
 }
+
+static inline int accel_cpu_exec(CPUState *env)
+{
+    return current_accel->cpu_exec(env);
+}
 #endif
cpu-exec.c +2 -3
index b47cf43..a0b6055 100644
@@ -336,9 +336,9 @@ int cpu_exec(CPUState *env1)
                 }
                 env->exception_index = -1;
             }
-#ifdef USE_KQEMU
+
             env->eflags = env->eflags | cc_table[CC_OP].compute_all()  | (DF & DF_MASK);
-            ret = kqemu_cpu_exec(env);
+            ret = accel_cpu_exec(env);
             env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
             if (ret == EXEC_EXIT_INTR) {
                 /* exception */
@@ -353,7 +353,6 @@ int cpu_exec(CPUState *env1)
                     longjmp(env->jmp_env, 1);
                 }
             }
-#endif
 
             next_tb = 0; /* force lookup of first TB */
             for(;;) {
exec-all.h +0 -1
index 6c62f06..8228746 100644
@@ -365,7 +365,6 @@ static inline int can_do_io(CPUState *env)
 
 #define MSR_QPI_COMMBASE 0xfabe0010
 
-int kqemu_cpu_exec(CPUState *env);
 void kqemu_set_phys_mem(uint64_t start_addr, ram_addr_t size, 
                         ram_addr_t phys_offset);
 void kqemu_record_dump(void);
kqemu.c +3 -2
index f99a4f1..5162d55 100644
@@ -731,7 +731,7 @@ static inline void kqemu_save_seg(SegmentCache *sc,
     sc->base = ksc->base;
 }
 
-int kqemu_do_cpu_exec(CPUState *env)
+static int kqemu_do_cpu_exec(CPUState *env)
 {
     struct kqemu_cpu_state kcpu_state, *kenv = &kcpu_state;
     int ret, cpl, i;
@@ -981,7 +981,7 @@ int kqemu_do_cpu_exec(CPUState *env)
     return EXEC_EXIT_DONE;
 }
 
-int kqemu_cpu_exec(CPUState *env)
+static int kqemu_cpu_exec(CPUState *env)
 {
 
     int ret = EXEC_EXIT_SOFTMMU;
@@ -1179,6 +1179,7 @@ QEMUAccel kqemu_accel = {
     .register_physical_memory = kqemu_set_phys_mem,
     .trace_io = kqemu_trace_io,
     .break_loop = kqemu_break_loop,
+    .cpu_exec = kqemu_cpu_exec,
 };
 
 #endif
Signature · 1 line
1.5.5.1
#66 lore raw

PATCH 26/32 provide two accelerators for kqemu

In reply to Glauber Costa

They are mostly equal, just ease the management of accel selecting options.

---
 kqemu.c  |  114 +++++++++++++++++++++++++++++++++++++++----------------------
 kqemu.h  |    1 -
 sysemu.h |    5 ---
 vl.c     |   19 +----------
 4 files changed, 74 insertions(+), 65 deletions(-)
kqemu.c +73 -41
index 5162d55..310a1af 100644
@@ -45,6 +45,10 @@
 
 #ifdef USE_KQEMU
 
+#define KQEMU_USER 1
+#define KQEMU_KERNEL 2
+
+static int kqemu_state;
 #define DEBUG
 //#define PROFILE
 
@@ -75,11 +79,6 @@ int kqemu_fd = KQEMU_INVALID_FD;
 #define kqemu_closefd(x) close(x)
 #endif
 
-/* 0 = not allowed
-   1 = user kqemu
-   2 = kernel kqemu
-*/
-int kqemu_allowed = 1;
 uint64_t *pages_to_flush;
 unsigned int nb_pages_to_flush;
 uint64_t *ram_pages_to_update;
@@ -131,20 +130,12 @@ static int is_cpuid_supported(void)
  */
 int kqemu_is_enabled(CPUState *env)
 {
-    if (strcasecmp(current_accel->name, "kqemu")) {
-        return 0;
-    }
-
-    return env->kqemu_enabled;
-
+    return kqemu_state == KQEMU_USER;
 }
 
 int kqemu_kernel_enabled(CPUState *env)
 {
-    if (strcasecmp(current_accel->name, "kqemu")) {
-        return 0;
-    }
-    return env->kqemu_enabled == 2;
+    return kqemu_state == KQEMU_KERNEL;
 }
 
 static void kqemu_update_cpuid(CPUState *env)
@@ -186,7 +177,7 @@ static void kqemu_update_cpuid(CPUState *env)
 
 QEMUAccel kqemu_accel;
 
-static int kqemu_start(int cpus)
+static int kqemu_do_start(int cpus)
 {
     struct kqemu_init kinit;
     int ret, version;
@@ -194,7 +185,7 @@ static int kqemu_start(int cpus)
     DWORD temp;
 #endif
 
-    if (!kqemu_allowed || cpus > 1)
+    if (cpus > 1)
         return -1;
 
 #ifdef _WIN32
@@ -273,10 +264,28 @@ static int kqemu_start(int cpus)
     return 0;
 }
 
+static int kqemu_start(int cpus)
+{
+    kqemu_state = KQEMU_USER;
+    return kqemu_do_start(cpus);
+}
+
+static int kqemu_start_kernel(int cpus)
+{
+    kqemu_state = KQEMU_KERNEL;
+    return kqemu_do_start(cpus);
+}
+
 static void kqemu_init_env(CPUState *env)
 {
     kqemu_update_cpuid(env);
-    env->kqemu_enabled = kqemu_allowed;
+    env->kqemu_enabled = 1;
+}
+
+static void kqemu_init_env_kernel(CPUState *env)
+{
+    kqemu_update_cpuid(env);
+    env->kqemu_enabled = 2;
 }
 
 static void kqemu_flush_page(CPUState *env, target_ulong addr)
@@ -791,7 +800,7 @@ static int kqemu_do_cpu_exec(CPUState *env)
     cpl = (env->hflags & HF_CPL_MASK);
     kenv->cpl = cpl;
     kenv->nb_pages_to_flush = nb_pages_to_flush;
-    kenv->user_only = (env->kqemu_enabled == 1);
+    kenv->user_only = kqemu_is_enabled(env);
     kenv->nb_ram_pages_to_update = nb_ram_pages_to_update;
     nb_ram_pages_to_update = 0;
     kenv->nb_modified_ram_pages = nb_modified_ram_pages;
@@ -1082,27 +1091,12 @@ static void qpi_init(void)
 
 static int kqemu_info(CPUState *env, char *buf)
 {
-    int val, len;
-    int bufsiz = MAX_INFO_BUF;
-    val = 0;
-    val = env->kqemu_enabled;
-    len = snprintf(buf, bufsiz, "kqemu support: ");
-    buf += len;
-    bufsiz -= len;
-
-    switch(val) {
-    default:
-        len += snprintf(buf, bufsiz, "present, but bogus value\n");
-        break;
-    case 1:
-        len += snprintf(buf, bufsiz, "enabled for user code\n");
-        break;
-    case 2:
-        len += snprintf(buf, bufsiz, "enabled for user and kernel code\n");
-        break;
-    }
+    return snprintf(buf, MAX_INFO_BUF, "kqemu support: enabled for user code\n");
+}
 
-    return len;
+static int kqemu_kernel_info(CPUState *env, char *buf)
+{
+    return snprintf(buf, MAX_INFO_BUF, "kqemu support: enabled for user and kernel code\n");
 }
 
 int64_t kqemu_time;
@@ -1141,10 +1135,27 @@ static void kqemu_trace_io(CPUState *env)
         kqemu_cpu_field(env,last_io_time) = cpu_get_time_fast();
 }
 
+#define MIN_CYCLE_BEFORE_SWITCH (100 * 1000)
+
+static inline int kqemu_flags_ok(CPUState *env)
+{
+    return((env->cr[0] & CR0_PE_MASK) &&
+           !(env->hflags & HF_INHIBIT_IRQ_MASK) &&
+           (env->eflags & IF_MASK) &&
+           !(env->eflags & VM_MASK));
+}
+
+static inline int kqemu_kernel_flags_ok(CPUState *env)
+{
+    return (kqemu_flags_ok(env) && (kqemu_kernel_enabled(env) ||
+            ((env->hflags & HF_CPL_MASK) == 3 &&
+             (env->eflags & IOPL_MASK) != IOPL_MASK)));
+
+}
+
 static int kqemu_break_loop(CPUState *env)
 {
-#define MIN_CYCLE_BEFORE_SWITCH (100 * 1000)
-    if (kqemu_is_ok(env) &&
+    if (kqemu_kernel_flags_ok(env) &&
         (cpu_get_time_fast() - kqemu_cpu_field(env,last_io_time)) >= MIN_CYCLE_BEFORE_SWITCH) {
         return 1;
     }
@@ -1182,4 +1193,25 @@ QEMUAccel kqemu_accel = {
     .cpu_exec = kqemu_cpu_exec,
 };
 
+QEMUAccel kqemu_kernel_accel = {
+    .name = "kernel-KQEMU",
+    .cpu_interrupt = kqemu_cpu_interrupt,
+    .init_env = kqemu_init_env_kernel,
+    .get_env = kqemu_get_env,
+    .start = kqemu_start_kernel,
+    .flush_cache = kqemu_flush,
+    .flush_page = kqemu_flush_page,
+    .info = kqemu_kernel_info,
+    .profile = kqemu_profile,
+    .set_notdirty = kqemu_set_notdirty,
+    .modify_page = kqemu_modify_page,
+#ifndef CONFIG_USER_ONLY
+    .get_real_ticks = cpu_get_real_ticks,
+#endif
+    .register_physical_memory = kqemu_set_phys_mem,
+    .trace_io = kqemu_trace_io,
+    .break_loop = kqemu_break_loop,
+    .cpu_exec = kqemu_cpu_exec,
+};
+
 #endif
kqemu.h +0 -1
index 62ba1d9..f644e41 100644
@@ -161,7 +161,6 @@ int kqemu_is_enabled(CPUState *env);
 int kqemu_kernel_enabled(CPUState *env);
 
 typedef struct KQEMUCPUstate {
-    int kqemu_enabled;
     int last_io_time;
     CPUState env;
 } KQEMUCPUState;
sysemu.h +0 -5
index 976fecc..5a19626 100644
@@ -99,11 +99,6 @@ extern int semihosting_enabled;
 extern int old_param;
 extern const char *bootp_filename;
 
-
-#ifdef USE_KQEMU
-extern int kqemu_allowed;
-#endif
-
 #define MAX_OPTION_ROMS 16
 extern const char *option_rom[MAX_OPTION_ROMS];
 extern int nb_option_roms;
vl.c +1 -18
index e64becb..42720e8 100644
@@ -259,6 +259,7 @@ QEMUAccel *available_accels[] = {
 /* list of available accelerators */
 #ifdef USE_KQEMU
     &kqemu_accel,
+    &kqemu_kernel_accel,
 #endif
 };
 
@@ -8236,10 +8237,6 @@ static void help(int exitcode)
            "-hdachs c,h,s[,t]  force hard disk 0 physical geometry and the optional BIOS\n"
            "                translation (t=none or lba) (usually qemu can guess them)\n"
            "-L path         set the directory for the BIOS, VGA BIOS and keymaps\n"
-#ifdef USE_KQEMU
-           "-kernel-kqemu   enable KQEMU full virtualization (default is user mode only)\n"
-           "-no-kqemu       disable KQEMU kernel module usage\n"
-#endif
 #ifdef TARGET_I386
            "-no-acpi        disable ACPI\n"
 #endif
@@ -8343,9 +8340,7 @@ enum {
     QEMU_OPTION_alt_grab,
     QEMU_OPTION_no_quit,
     QEMU_OPTION_pidfile,
-    QEMU_OPTION_no_kqemu,
     QEMU_OPTION_accel,
-    QEMU_OPTION_kernel_kqemu,
     QEMU_OPTION_win2k_hack,
     QEMU_OPTION_usb,
     QEMU_OPTION_usbdevice,
@@ -8428,10 +8423,6 @@ static const QEMUOption qemu_options[] = {
     { "hdachs", HAS_ARG, QEMU_OPTION_hdachs },
     { "L", HAS_ARG, QEMU_OPTION_L },
     { "bios", HAS_ARG, QEMU_OPTION_bios },
-#ifdef USE_KQEMU
-    { "no-kqemu", 0, QEMU_OPTION_no_kqemu },
-    { "kernel-kqemu", 0, QEMU_OPTION_kernel_kqemu },
-#endif
     { "accel", HAS_ARG, QEMU_OPTION_accel},
 #if defined(TARGET_PPC) || defined(TARGET_SPARC)
     { "g", 1, QEMU_OPTION_g },
@@ -9247,14 +9238,6 @@ int main(int argc, char **argv)
                 win2k_install_hack = 1;
                 break;
 #endif
-#ifdef USE_KQEMU
-            case QEMU_OPTION_no_kqemu:
-                kqemu_allowed = 0;
-                break;
-            case QEMU_OPTION_kernel_kqemu:
-                kqemu_allowed = 2;
-                break;
-#endif
             case QEMU_OPTION_accel:
                 {
                     int i;
Signature · 1 line
1.5.5.1
#67 lore raw

PATCH 27/32 arch-specific hooks for accelerator

In reply to Glauber Costa

This patch provides an arch field in QEMUAccel. It will be used initially for x86, to replace kqemu code in op_helper.c We start with get_msr and set_msr functions, that allow accelerators to handle non-default msrs.

---
 accel.h                 |    1 +
 exec-all.h              |    2 --
 kqemu.c                 |   26 +++++++++++++++++++++++++-
 target-i386/accel86.h   |   28 ++++++++++++++++++++++++++++
 target-i386/op_helper.c |   14 +++-----------
 5 files changed, 57 insertions(+), 14 deletions(-)
 create mode 100644 target-i386/accel86.h
accel.h +1 -0
index 1741f06..00a495c 100644
@@ -23,6 +23,7 @@ typedef struct QEMUAccel {
     void (*trace_io)(CPUState *env);
     int (*break_loop)(CPUState *env);
     int (*cpu_exec)(CPUState *env);
+    void *arch; /* arch-specific accel functions */
 } QEMUAccel;
 
 typedef struct QEMUCont {
exec-all.h +0 -2
index 8228746..1e9aa5a 100644
@@ -369,8 +369,6 @@ void kqemu_set_phys_mem(uint64_t start_addr, ram_addr_t size,
                         ram_addr_t phys_offset);
 void kqemu_record_dump(void);
 
-extern uint32_t kqemu_comm_base;
-
 static inline int kqemu_is_ok(CPUState *env)
 {
     return(env->kqemu_enabled &&
kqemu.c +25 -1
index 310a1af..cab6354 100644
@@ -55,7 +55,7 @@ static int kqemu_state;
 #include <unistd.h>
 #include <fcntl.h>
 #include "kqemu.h"
-#include "accel.h"
+#include "accel86.h"
 
 #ifdef CONFIG_PROFILER
 #include "qemu-timer.h" /* for ticks_per_sec */
@@ -1169,6 +1169,28 @@ static CPUState *kqemu_get_env(void)
     return &kenv->env;
 }
 
+static int kqemu_get_msr(int msr, uint64_t *val)
+{
+    int ret = -1;
+    switch (msr) {
+    case MSR_QPI_COMMBASE:
+        val = kqemu_comm_base;
+        ret = 0;
+        break;
+    }
+    return ret;
+}
+
+static int kqemu_set_msr(int msr, target_ulong val)
+{
+    return -1;
+}
+
+QEMUAccel86 kqemu_accel86 = {
+    .get_msr = kqemu_get_msr,
+    .set_msr = kqemu_set_msr,
+};
+
 QEMUAccel kqemu_accel = {
     .name = "KQEMU",
     .cpu_interrupt = kqemu_cpu_interrupt,
@@ -1191,6 +1213,7 @@ QEMUAccel kqemu_accel = {
     .trace_io = kqemu_trace_io,
     .break_loop = kqemu_break_loop,
     .cpu_exec = kqemu_cpu_exec,
+    .arch = &kqemu_accel86,
 };
 
 QEMUAccel kqemu_kernel_accel = {
@@ -1212,6 +1235,7 @@ QEMUAccel kqemu_kernel_accel = {
     .trace_io = kqemu_trace_io,
     .break_loop = kqemu_break_loop,
     .cpu_exec = kqemu_cpu_exec,
+    .arch = &kqemu_accel86,
 };
 
 #endif
target-i386/accel86.h new file +28 -0
new file mode 100644
index 0000000..142d63e
@@ -0,0 +1,28 @@
+#ifndef _ACCEL_86_H_
+#define _ACCEL_86_H_
+
+#include "accel.h"
+
+typedef struct QEMUAccel86 {
+	int (*get_msr)(int msr, uint64_t *value);
+	int (*set_msr)(int msr, uint64_t value);
+} QEMUAccel86;
+
+#define accel86_call_func ((QEMUAccel86 *)(current_accel->arch))
+
+static inline int accel_get_msr(int msr, uint64_t *value)
+{
+    if (!current_accel->arch)
+        return -1;
+    return accel86_call_func->get_msr(msr, value);
+}
+
+static inline int accel_set_msr(int msr, uint64_t value)
+{
+    if (!current_accel->arch)
+        return -1;
+    return accel86_call_func->set_msr(msr, value);
+}
+
+#endif
+
target-i386/op_helper.c +3 -11
index ebb5824..fe8ddf8 100644
@@ -20,6 +20,7 @@
 #define CPU_NO_GLOBAL_REGS
 #include "exec.h"
 #include "host-utils.h"
+#include "accel86.h"
 
 //#define DEBUG_PCALL
 
@@ -3262,18 +3263,9 @@ void helper_rdmsr(void)
         val = env->kernelgsbase;
         break;
 #endif
-#ifdef USE_KQEMU
-    case MSR_QPI_COMMBASE:
-        if (env->kqemu_enabled) {
-            val = kqemu_comm_base;
-        } else {
-            val = 0;
-        }
-        break;
-#endif
     default:
-        /* XXX: exception ? */
-        val = 0;
+        if (accel_get_msr((uint32_t)ECX, &val) < 0)
+            val = 0;
         break;
     }
     EAX = (uint32_t)(val);
Signature · 1 line
1.5.5.1
#68 lore raw

[Qemu-devel] Re: [PATCH 27/32] arch-specific hooks for accelerator

accel.h typedef struct QEMUAccel { · line 27

Quoted 11 lines · Glauber Costa

This patch provides an arch field in QEMUAccel. It will be used initially for x86, to replace kqemu code in op_helper.c We start with get_msr and set_msr functions, that allow accelerators to handle non-default msrs.

accel.h +1 -0
@@ -23,6 +23,7 @@ typedef struct QEMUAccel {
     void (*trace_io)(CPUState *env);
     int (*break_loop)(CPUState *env);
     int (*cpu_exec)(CPUState *env);
+    void *arch; /* arch-specific accel functions */
 } QEMUAccel

This is more elegant IMO using container_of() and including the common part as a member. Less pointers to chase.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#69 lore raw

[Qemu-devel] Re: [PATCH 27/32] arch-specific hooks for accelerator

Quoted 6 lines · Avi Kivity
Quoted 5 lines · Glauber Costa

This patch provides an arch field in QEMUAccel. It will be used initially for x86, to replace kqemu code in op_helper.c We start with get_msr and set_msr functions, that allow accelerators to handle non-default msrs.

Quoted 9 lines

accel.h typedef struct QEMUAccel { · line 27

Quoted 6 lines
accel.h +1 -0
@@ -23,6 +23,7 @@ typedef struct QEMUAccel {
     void (*trace_io)(CPUState *env);
     int (*break_loop)(CPUState *env);
     int (*cpu_exec)(CPUState *env);
+    void *arch; /* arch-specific accel functions */
 } QEMUAccel

This is more elegant IMO using container_of() and including the common part as a member. Less pointers to chase.

...or to have some kind of QEMUAccel_arch, defined in target-*/accel.h files. Haven't looked into the use cases yet to say what is sufficient.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#70 lore raw

[Qemu-devel] Re: [PATCH 27/32] arch-specific hooks for accelerator

Quoted 6 lines · Jan Kiszka
Quoted 6 lines
Quoted 6 lines
     void (*trace_io)(CPUState *env);
     int (*break_loop)(CPUState *env);
     int (*cpu_exec)(CPUState *env);

+ void *arch; /* arch-specific accel functions */
} QEMUAccel

Quoted 7 lines
Quoted 3 lines

This is more elegant IMO using container_of() and including the common part as a member. Less pointers to chase.

...or to have some kind of QEMUAccel_arch, defined in target-*/accel.h files. Haven't looked into the use cases yet to say what is sufficient.

You're right, there's no need for run-time dynamic types here.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#71 lore raw

PATCH 28/32 iret arch specific accelerator

In reply to Glauber Costa

let arch-specific accelerator hook into the end of interrupt return.

---
 kqemu.c                 |   10 ++++++++++
 target-i386/accel86.h   |    8 ++++++++
 target-i386/op_helper.c |    9 ++-------
 3 files changed, 20 insertions(+), 7 deletions(-)
kqemu.c +10 -0
index cab6354..0bea20e 100644
@@ -1186,9 +1186,19 @@ static int kqemu_set_msr(int msr, target_ulong val)
     return -1;
 }
 
+static void kqemu_interrupt_return(CPUState *env)
+{
+    if (kqemu_kernel_flags_ok(env)) {
+        CC_OP = CC_OP_EFLAGS;
+        env->exception_index = -1;
+        cpu_loop_exit();
+    }
+}
+
 QEMUAccel86 kqemu_accel86 = {
     .get_msr = kqemu_get_msr,
     .set_msr = kqemu_set_msr,
+    .interrupt_return = kqemu_interrupt_return,
 };
 
 QEMUAccel kqemu_accel = {
target-i386/accel86.h +8 -0
index 142d63e..c3201f5 100644
@@ -6,6 +6,7 @@
 typedef struct QEMUAccel86 {
 	int (*get_msr)(int msr, uint64_t *value);
 	int (*set_msr)(int msr, uint64_t value);
+    void (*interrupt_return)(CPUState *env);
 } QEMUAccel86;
 
 #define accel86_call_func ((QEMUAccel86 *)(current_accel->arch))
@@ -24,5 +25,12 @@ static inline int accel_set_msr(int msr, uint64_t value)
     return accel86_call_func->set_msr(msr, value);
 }
 
+static inline void accel_interrupt_return(CPUState *env)
+{
+    if (!current_accel->arch)
+        return;
+    accel86_call_func->interrupt_return(env);
+}
+
 #endif
 
target-i386/op_helper.c +2 -7
index fe8ddf8..61ba6fc 100644
@@ -2918,13 +2918,8 @@ void helper_iret_protected(int shift, int next_eip)
         helper_ret_protected(shift, 1, 0);
     }
     env->hflags2 &= ~HF2_NMI_MASK;
-#ifdef USE_KQEMU
-    if (kqemu_is_ok(env)) {
-        CC_OP = CC_OP_EFLAGS;
-        env->exception_index = -1;
-        cpu_loop_exit();
-    }
-#endif
+
+    accel_interrupt_return(env);
 }
 
 void helper_lret_protected(int shift, int addend)
Signature · 1 line
1.5.5.1
#72 lore raw

PATCH 29/32 sysret/sysexit arch specific accelerator

In reply to Glauber Costa

let arch-specific accelerator hook into the end of syscall return functions sysret and sysexit.

---
 kqemu.c                 |   11 +++++++++++
 target-i386/accel86.h   |    8 ++++++++
 target-i386/op_helper.c |   15 +--------------
 3 files changed, 20 insertions(+), 14 deletions(-)
kqemu.c +11 -0
index 0bea20e..1934aa5 100644
@@ -1195,10 +1195,21 @@ static void kqemu_interrupt_return(CPUState *env)
     }
 }
 
+static void kqemu_syscall_return(CPUState *env)
+{
+    if (kqemu_kernel_flags_ok(env)) {
+        if (env->hflags & HF_LMA_MASK)
+            CC_OP = CC_OP_EFLAGS;
+        env->exception_index = -1;
+        cpu_loop_exit();
+    }
+}
+
 QEMUAccel86 kqemu_accel86 = {
     .get_msr = kqemu_get_msr,
     .set_msr = kqemu_set_msr,
     .interrupt_return = kqemu_interrupt_return,
+    .syscall_return = kqemu_syscall_return,
 };
 
 QEMUAccel kqemu_accel = {
target-i386/accel86.h +8 -0
index c3201f5..1624a64 100644
@@ -7,6 +7,7 @@ typedef struct QEMUAccel86 {
 	int (*get_msr)(int msr, uint64_t *value);
 	int (*set_msr)(int msr, uint64_t value);
     void (*interrupt_return)(CPUState *env);
+    void (*syscall_return)(CPUState *env);
 } QEMUAccel86;
 
 #define accel86_call_func ((QEMUAccel86 *)(current_accel->arch))
@@ -32,5 +33,12 @@ static inline void accel_interrupt_return(CPUState *env)
     accel86_call_func->interrupt_return(env);
 }
 
+static inline void accel_syscall_return(CPUState *env)
+{
+    if (!current_accel->arch)
+        return;
+    accel86_call_func->syscall_return(env);
+}
+
 #endif
 
target-i386/op_helper.c +1 -14
index 61ba6fc..a831a4d 100644
@@ -1104,14 +1104,7 @@ void helper_sysret(int dflag)
         env->eflags |= IF_MASK;
         cpu_x86_set_cpl(env, 3);
     }
-#ifdef USE_KQEMU
-    if (kqemu_is_ok(env)) {
-        if (env->hflags & HF_LMA_MASK)
-            CC_OP = CC_OP_EFLAGS;
-        env->exception_index = -1;
-        cpu_loop_exit();
-    }
-#endif
+    accel_syscall_return(env);
 }
 
 /* real mode interrupt */
@@ -3003,12 +2996,6 @@ void helper_sysexit(int dflag)
     }
     ESP = ECX;
     EIP = EDX;
-#ifdef USE_KQEMU
-    if (kqemu_is_ok(env)) {
-        env->exception_index = -1;
-        cpu_loop_exit();
-    }
-#endif
 }
 
 #if defined(CONFIG_USER_ONLY)
Signature · 1 line
1.5.5.1
#73 lore raw

PATCH 30/32 lcall/lret arch specific accel hooks

In reply to Glauber Costa

provide arch specific hooks for far calls in op_helper.c

---
 kqemu.c                 |   10 ++++++++++
 target-i386/accel86.h   |   16 ++++++++++++++++
 target-i386/op_helper.c |   14 ++------------
 3 files changed, 28 insertions(+), 12 deletions(-)
kqemu.c +10 -0
index 1934aa5..7b87a58 100644
@@ -1205,11 +1205,21 @@ static void kqemu_syscall_return(CPUState *env)
     }
 }
 
+static void kqemu_long_exit_loop(CPUState *env)
+{
+    if (kqemu_kernel_flags_ok(env)) {
+        env->exception_index = -1;
+        cpu_loop_exit();
+    }
+}
+
 QEMUAccel86 kqemu_accel86 = {
     .get_msr = kqemu_get_msr,
     .set_msr = kqemu_set_msr,
     .interrupt_return = kqemu_interrupt_return,
     .syscall_return = kqemu_syscall_return,
+    .long_call = kqemu_long_exit_loop,
+    .long_ret = kqemu_long_exit_loop,
 };
 
 QEMUAccel kqemu_accel = {
target-i386/accel86.h +16 -0
index 1624a64..a7ba39b 100644
@@ -8,6 +8,8 @@ typedef struct QEMUAccel86 {
 	int (*set_msr)(int msr, uint64_t value);
     void (*interrupt_return)(CPUState *env);
     void (*syscall_return)(CPUState *env);
+    void (*long_call)(CPUState *env);
+    void (*long_ret)(CPUState *env);
 } QEMUAccel86;
 
 #define accel86_call_func ((QEMUAccel86 *)(current_accel->arch))
@@ -40,5 +42,19 @@ static inline void accel_syscall_return(CPUState *env)
     accel86_call_func->syscall_return(env);
 }
 
+static inline void accel_long_call(CPUState *env)
+{
+    if (!current_accel->arch)
+        return;
+    accel86_call_func->syscall_return(env);
+}
+
+static inline void accel_long_ret(CPUState *env)
+{
+    if (!current_accel->arch)
+        return;
+    accel86_call_func->syscall_return(env);
+}
+
 #endif
 
target-i386/op_helper.c +2 -12
index a831a4d..addd42a 100644
@@ -2617,12 +2617,7 @@ void helper_lcall_protected(int new_cs, target_ulong new_eip,
         SET_ESP(sp, sp_mask);
         EIP = offset;
     }
-#ifdef USE_KQEMU
-    if (kqemu_is_ok(env)) {
-        env->exception_index = -1;
-        cpu_loop_exit();
-    }
-#endif
+    accel_long_call(env);
 }
 
 /* real and vm86 mode iret */
@@ -2918,12 +2913,7 @@ void helper_iret_protected(int shift, int next_eip)
 void helper_lret_protected(int shift, int addend)
 {
     helper_ret_protected(shift, 0, addend);
-#ifdef USE_KQEMU
-    if (kqemu_is_ok(env)) {
-        env->exception_index = -1;
-        cpu_loop_exit();
-    }
-#endif
+    accel_long_ret(env);
 }
 
 void helper_sysenter(void)
Signature · 1 line
1.5.5.1
#74 lore raw

PATCH 31/32 remove kqemu_is_ok tests.

In reply to Glauber Costa

Replace kqemu_is_ok with local tests, since they it is not used anywhere else in the code.

---
 exec-all.h        |   12 ------------
 kqemu.c           |   11 ++---------
 target-i386/cpu.h |    3 ---
 3 files changed, 2 insertions(+), 24 deletions(-)
exec-all.h +0 -12
index 1e9aa5a..55972ac 100644
@@ -369,17 +369,5 @@ void kqemu_set_phys_mem(uint64_t start_addr, ram_addr_t size,
                         ram_addr_t phys_offset);
 void kqemu_record_dump(void);
 
-static inline int kqemu_is_ok(CPUState *env)
-{
-    return(env->kqemu_enabled &&
-           (env->cr[0] & CR0_PE_MASK) &&
-           !(env->hflags & HF_INHIBIT_IRQ_MASK) &&
-           (env->eflags & IF_MASK) &&
-           !(env->eflags & VM_MASK) &&
-           (env->kqemu_enabled == 2 ||
-            ((env->hflags & HF_CPL_MASK) == 3 &&
-             (env->eflags & IOPL_MASK) != IOPL_MASK)));
-}
-
 #endif
 #endif
kqemu.c +2 -9
index 7b87a58..58a149b 100644
@@ -279,13 +279,6 @@ static int kqemu_start_kernel(int cpus)
 static void kqemu_init_env(CPUState *env)
 {
     kqemu_update_cpuid(env);
-    env->kqemu_enabled = 1;
-}
-
-static void kqemu_init_env_kernel(CPUState *env)
-{
-    kqemu_update_cpuid(env);
-    env->kqemu_enabled = 2;
 }
 
 static void kqemu_flush_page(CPUState *env, target_ulong addr)
@@ -994,7 +987,7 @@ static int kqemu_cpu_exec(CPUState *env)
 {
 
     int ret = EXEC_EXIT_SOFTMMU;
-    if (kqemu_is_ok(env) && env->interrupt_request == 0) {
+    if (kqemu_kernel_flags_ok(env) && env->interrupt_request == 0) {
         ret = kqemu_do_cpu_exec(env);
         /* put eflags in CPU temporary format */
         CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
@@ -1250,7 +1243,7 @@ QEMUAccel kqemu_accel = {
 QEMUAccel kqemu_kernel_accel = {
     .name = "kernel-KQEMU",
     .cpu_interrupt = kqemu_cpu_interrupt,
-    .init_env = kqemu_init_env_kernel,
+    .init_env = kqemu_init_env,
     .get_env = kqemu_get_env,
     .start = kqemu_start_kernel,
     .flush_cache = kqemu_flush,
target-i386/cpu.h +0 -3
index 6310529..e5e91cc 100644
@@ -606,9 +606,6 @@ typedef struct CPUX86State {
     uint32_t cpuid_ext3_features;
     uint32_t cpuid_apic_id;
 
-#ifdef USE_KQEMU
-    int kqemu_enabled;
-#endif
     /* in order to simplify APIC support, we leave this pointer to the
        user */
     struct APICState *apic_state;
Signature · 1 line
1.5.5.1
#75 lore raw

PATCH 32/32 clean up kqemu code

In reply to Glauber Costa

Remove bits from kqemu.h that are no longer used outside of kqemu files scope. The ones which are still needed are moved to kqemu.h

---
 exec-all.h |   10 ----------
 kqemu.h    |    3 +++
 2 files changed, 3 insertions(+), 10 deletions(-)
exec-all.h +0 -10
index 55972ac..fa4a4eb 100644
@@ -360,14 +360,4 @@ static inline int can_do_io(CPUState *env)
 #define EXEC_EXIT_INTR 1
 #define EXEC_EXIT_SOFTMMU 2
 
-#ifdef USE_KQEMU
-#define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))
-
-#define MSR_QPI_COMMBASE 0xfabe0010
-
-void kqemu_set_phys_mem(uint64_t start_addr, ram_addr_t size, 
-                        ram_addr_t phys_offset);
-void kqemu_record_dump(void);
-
-#endif
 #endif
kqemu.h +3 -0
index f644e41..4152fbd 100644
@@ -169,4 +169,7 @@ typedef struct KQEMUCPUstate {
     KQEMUCPUState *__c = container_of(env, KQEMUCPUState, env); \
     &__c->field; }))
 
+#define KQEMU_MODIFY_PAGE_MASK (0xff & ~(VGA_DIRTY_FLAG | CODE_DIRTY_FLAG))
+
+#define MSR_QPI_COMMBASE 0xfabe0010
 #endif /* KQEMU_H */
Signature · 1 line
1.5.5.1
#76 lore raw
In reply to Glauber Costa
Quoted 21 lines · Glauber Costa

Hi guys,

I'm sending here a new version of the accel patch. It comprises the cleaned up version I've last sent, plus a few additions

You may want to pay special attention to the additions, since they are newcomers to the series. To ease your job, they are:

0001-use-anonymous-memory-for-kqemu.patch 0002-protect-exec-all.h-frm-multiple-inclusion.patch 0003-change-definition-of-FILE-for-linux.patch 0005-use-more-meaningful-values-for-kqemu_cpu_exec.patch 0025-provide-accel-hook-for-cpu_exec.patch 0026-provide-two-accelerators-for-kqemu.patch 0027-arch-specific-hooks-for-accelerator.patch 0028-iret-arch-specific-accelerator.patch 0029-sysret-sysexit-arch-specific-accelerator.patch 0030-lcall-lret-arch-specific-accel-hooks.patch 0031-remove-kqemu_is_ok-tests.patch 0032-clean-up-kqemu-code.patch

Quoted 6 lines

git users can get a snapshot of it located at

git://git.kernel.org/pub/scm/virt/glommer/qemu-accel.git accel-v2

diffstat and OBP (One Big Patch ;-)) attached.

Careful question: Build-tested against other OSes beyond /The OS/ ;)?

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#77 lore raw
Quoted 22 lines · Jan Kiszka
Quoted 21 lines · Glauber Costa

Hi guys,

I'm sending here a new version of the accel patch. It comprises the cleaned up version I've last sent, plus a few additions

You may want to pay special attention to the additions, since they are newcomers to the series. To ease your job, they are:

0001-use-anonymous-memory-for-kqemu.patch 0002-protect-exec-all.h-frm-multiple-inclusion.patch 0003-change-definition-of-FILE-for-linux.patch 0005-use-more-meaningful-values-for-kqemu_cpu_exec.patch 0025-provide-accel-hook-for-cpu_exec.patch 0026-provide-two-accelerators-for-kqemu.patch 0027-arch-specific-hooks-for-accelerator.patch 0028-iret-arch-specific-accelerator.patch 0029-sysret-sysexit-arch-specific-accelerator.patch 0030-lcall-lret-arch-specific-accel-hooks.patch 0031-remove-kqemu_is_ok-tests.patch 0032-clean-up-kqemu-code.patch

Quoted 8 lines
Quoted 6 lines

git users can get a snapshot of it located at

git://git.kernel.org/pub/scm/virt/glommer/qemu-accel.git accel-v2

diffstat and OBP (One Big Patch ;-)) attached.

Careful question: Build-tested against other OSes beyond /The OS/ ;)?

No. I only have a Linux environment right now.

Quoted 6 lines

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
#78 lore raw
Quoted 3 lines · Glauber Costa

No. I only have a Linux environment right now.

Surely you have a Windows VM somewhere? It should be tested both as a guest and as a host.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#79 lore raw
In reply to Glauber Costa
Quoted 21 lines · Glauber Costa

Hi guys,

I'm sending here a new version of the accel patch. It comprises the cleaned up version I've last sent, plus a few additions

You may want to pay special attention to the additions, since they are newcomers to the series. To ease your job, they are:

0001-use-anonymous-memory-for-kqemu.patch 0002-protect-exec-all.h-frm-multiple-inclusion.patch 0003-change-definition-of-FILE-for-linux.patch 0005-use-more-meaningful-values-for-kqemu_cpu_exec.patch 0025-provide-accel-hook-for-cpu_exec.patch 0026-provide-two-accelerators-for-kqemu.patch 0027-arch-specific-hooks-for-accelerator.patch 0028-iret-arch-specific-accelerator.patch 0029-sysret-sysexit-arch-specific-accelerator.patch 0030-lcall-lret-arch-specific-accel-hooks.patch 0031-remove-kqemu_is_ok-tests.patch 0032-clean-up-kqemu-code.patch

Quoted 6 lines

git users can get a snapshot of it located at

git://git.kernel.org/pub/scm/virt/glommer/qemu-accel.git accel-v2

diffstat and OBP (One Big Patch ;-)) attached.

So in general, the patches need better descriptions. Also, some of this is going to need Fabrice's ack. I'll try to be specific for those in follow-up notes.

Regards,

Anthony Liguori