From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LHMrq-0005Y1-Qp for qemu-devel@nongnu.org; Mon, 29 Dec 2008 13:29:30 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LHMrp-0005XE-1S for qemu-devel@nongnu.org; Mon, 29 Dec 2008 13:29:30 -0500 Received: from [199.232.76.173] (port=55322 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LHMro-0005X6-Rb for qemu-devel@nongnu.org; Mon, 29 Dec 2008 13:29:28 -0500 Received: from mx2.redhat.com ([66.187.237.31]:54830) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LHMro-00046o-De for qemu-devel@nongnu.org; Mon, 29 Dec 2008 13:29:28 -0500 From: Glauber Costa Date: Mon, 29 Dec 2008 13:29:22 -0500 Message-Id: <1230575362-14485-1-git-send-email-glommer@redhat.com> Subject: [Qemu-devel] [PATCH] hook cpu running at a higher level. Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Ian.Jackson@eu.citrix.com, avi@redhat.com, kvm@vger.kernel.org, stefano.stabellini@eu.citrix.com This patch removes the kvm_enabled() check from cpu-exec.c. This file is highly tcg-specific, and we'll probably want it out when tcg is not compiled in (coming soon, in a theathe near you) Instead, we hook at the main loop level. The amount of code duplication introduced is at worst, acceptable, and I believe it pays. The tcg mainloop is likely to be different from the hypervisors ones, since tcg runs all cpus in lockstep. KVM (and probably xen), will be able to span threads out for its vcpus. Signed-off-by: Glauber Costa --- cpu-exec.c | 5 ----- kvm-all.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ vl.c | 16 ++++++++++------ 3 files changed, 60 insertions(+), 11 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index ed1545b..be8ceac 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -333,11 +333,6 @@ int cpu_exec(CPUState *env1) } #endif - if (kvm_enabled()) { - kvm_cpu_exec(env); - longjmp(env->jmp_env, 1); - } - next_tb = 0; /* force lookup of first TB */ for(;;) { interrupt_request = env->interrupt_request; diff --git a/kvm-all.c b/kvm-all.c index 11034df..a279d6c 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -663,3 +663,53 @@ int kvm_has_sync_mmu(void) return 0; } + +extern CPUState *cur_cpu; +extern CPUState *next_cpu; + +extern int reset_requested; +extern int shutdown_requested; +extern int powerdown_requested; + +int kvm_main_loop(void) +{ + + int ret, timeout; + CPUState *env; + + cur_cpu = first_cpu; + next_cpu = first_cpu; + env = first_cpu; + + for(;;) { + /* get next cpu */ + cpu_single_env = env; + ret = kvm_cpu_exec(env); + cpu_single_env = NULL; + + if (shutdown_requested) + break; + if (reset_requested) { + reset_requested = 0; + qemu_system_reset(); + ret = EXCP_INTERRUPT; + } + if (powerdown_requested) { + powerdown_requested = 0; + qemu_system_powerdown(); + ret = EXCP_INTERRUPT; + } + + if (ret == EXCP_HALTED) { + timeout = 5000; + } else { + timeout = 0; + } + + main_loop_wait(timeout); + } + cpu_disable_ticks(); + return ret; +} + + diff --git a/vl.c b/vl.c index 0a02151..bcaccc3 100644 --- a/vl.c +++ b/vl.c @@ -248,8 +248,8 @@ static struct drive_opt { char opt[1024]; } drives_opt[MAX_DRIVES]; -static CPUState *cur_cpu; -static CPUState *next_cpu; +CPUState *cur_cpu; +CPUState *next_cpu; static int event_pending = 1; /* Conversion factor from emulated instructions to virtual clock ticks. */ static int icount_time_shift; @@ -3452,9 +3452,9 @@ typedef struct QEMUResetEntry { } QEMUResetEntry; static QEMUResetEntry *first_reset_entry; -static int reset_requested; -static int shutdown_requested; -static int powerdown_requested; +int reset_requested; +int shutdown_requested; +int powerdown_requested; int qemu_shutdown_requested(void) { @@ -5535,7 +5535,11 @@ int main(int argc, char **argv, char **envp) close(fd); } - main_loop(); + if (kvm_enabled()) + kvm_main_loop(); + else + main_loop(); + quit_timers(); net_cleanup(); -- 1.5.6.5