From patchwork Fri May 27 12:19:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 823642 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4RCJfwb026958 for ; Fri, 27 May 2011 12:19:42 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753925Ab1E0MTi (ORCPT ); Fri, 27 May 2011 08:19:38 -0400 Received: from goliath.siemens.de ([192.35.17.28]:33027 "EHLO goliath.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753785Ab1E0MTb (ORCPT ); Fri, 27 May 2011 08:19:31 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.13.6/8.13.6) with ESMTP id p4RCJP4a014790; Fri, 27 May 2011 14:19:25 +0200 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id p4RCJOKn005557; Fri, 27 May 2011 14:19:25 +0200 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org Subject: [PATCH 13/20] qemu-kvm: Use upstream vcpu pause/resume Date: Fri, 27 May 2011 14:19:17 +0200 Message-Id: X-Mailer: git-send-email 1.7.1 In-Reply-To: References: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 27 May 2011 12:19:42 +0000 (UTC) Signed-off-by: Jan Kiszka --- cpus.c | 84 ++++++++----------------------------------------------------- sysemu.h | 1 + vl.c | 6 +--- 3 files changed, 13 insertions(+), 78 deletions(-) diff --git a/cpus.c b/cpus.c index 9b3f218..470ab00 100644 --- a/cpus.c +++ b/cpus.c @@ -582,7 +582,6 @@ void run_on_cpu(CPUState *env, void (*func)(void *data), void *data) func(data); } -#endif /* !IOTHREAD */ void resume_all_vcpus(void) { } @@ -590,7 +589,6 @@ void resume_all_vcpus(void) void pause_all_vcpus(void) { } -#ifndef CONFIG_IOTHREAD void qemu_cpu_kick(void *env) { @@ -624,7 +622,6 @@ void qemu_notify_event(void) void qemu_mutex_lock_iothread(void) {} void qemu_mutex_unlock_iothread(void) {} -#endif /* !IOTHREAD */ void cpu_stop_current(void) { } @@ -633,16 +630,15 @@ void vm_stop(int reason) { do_vm_stop(reason); } -#ifndef CONFIG_IOTHREAD #else /* CONFIG_IOTHREAD */ QemuMutex qemu_global_mutex; static QemuMutex qemu_fair_mutex; -#ifdef UNUSED_IOTHREAD_IMPL static QemuThread io_thread; +#ifdef UNUSED_IOTHREAD_IMPL static QemuThread *tcg_cpu_thread; static QemuCond *tcg_halt_cond; #endif @@ -930,7 +926,6 @@ void qemu_mutex_unlock_iothread(void) qemu_mutex_unlock(&qemu_global_mutex); } -#ifdef UNUSED_IOTHREAD_IMPL static int all_vcpus_paused(void) { CPUState *penv = first_cpu; @@ -977,6 +972,7 @@ void resume_all_vcpus(void) } } +#ifdef UNUSED_IOTHREAD_IMPL static void qemu_tcg_init_vcpu(void *_env) { CPUState *env = _env; @@ -1028,7 +1024,6 @@ void qemu_notify_event(void) qemu_event_increment(); } -#ifdef UNUSED_IOTHREAD_IMPL void cpu_stop_current(void) { if (cpu_single_env) { @@ -1052,7 +1047,6 @@ void vm_stop(int reason) } do_vm_stop(reason); } -#endif /* UNUSED_IOTHREAD_IMPL */ #endif @@ -1264,65 +1258,6 @@ static void kvm_main_loop_wait(CPUState *env, int timeout) env->thread_kicked = false; } -static int all_threads_paused(void) -{ - CPUState *penv = first_cpu; - - while (penv) { - if (penv->stop) { - return 0; - } - penv = (CPUState *) penv->next_cpu; - } - - return 1; -} - -static void pause_all_threads(void) -{ - CPUState *penv = first_cpu; - - while (penv) { - if (!qemu_cpu_is_self(penv)) { - penv->stop = 1; - if (!penv->thread_kicked) { - pthread_kill(penv->thread->thread, SIG_IPI); - penv->thread_kicked = true; - } - } else { - penv->stop = 0; - penv->stopped = 1; - cpu_exit(penv); - } - penv = (CPUState *) penv->next_cpu; - } - - while (!all_threads_paused()) { - qemu_cond_wait(&qemu_pause_cond, &qemu_global_mutex); - } -} - -static void resume_all_threads(void) -{ - CPUState *penv = first_cpu; - - while (penv) { - penv->stop = 0; - penv->stopped = 0; - pthread_kill(penv->thread->thread, SIG_IPI); - penv = (CPUState *) penv->next_cpu; - } -} - -static void kvm_vm_state_change_handler(void *context, int running, int reason) -{ - if (running) { - resume_all_threads(); - } else { - pause_all_threads(); - } -} - static void setup_kernel_sigmask(CPUState *env) { sigset_t set; @@ -1342,12 +1277,12 @@ static void setup_kernel_sigmask(CPUState *env) static void qemu_kvm_system_reset(void) { - pause_all_threads(); + pause_all_vcpus(); cpu_synchronize_all_states(); qemu_system_reset(); - resume_all_threads(); + resume_all_vcpus(); } static int kvm_main_loop_cpu(CPUState *env) @@ -1420,8 +1355,6 @@ int kvm_init_ap(void) qemu_mutex_lock(&qemu_global_mutex); - qemu_add_vm_change_state_handler(kvm_vm_state_change_handler, NULL); - signal(SIG_IPI, sig_ipi_handler); memset(&action, 0, sizeof(action)); @@ -1440,7 +1373,7 @@ bool qemu_system_is_ready(void) int kvm_main_loop(void) { sigset_t mask; - int sigfd; + int sigfd, r; qemu_system_ready = 1; @@ -1482,10 +1415,13 @@ int kvm_main_loop(void) vm_stop(VMSTOP_DEBUG); kvm_debug_cpu_requested = NULL; } + if ((r = qemu_vmstop_requested())) { + vm_stop(r); + } } bdrv_close_all(); - pause_all_threads(); + pause_all_vcpus(); qemu_mutex_unlock(&qemu_global_mutex); return 0; @@ -1500,6 +1436,8 @@ static void qemu_kvm_init_main_loop(void) qemu_mutex_init(&qemu_fair_mutex); qemu_mutex_init(&qemu_global_mutex); qemu_mutex_lock(&qemu_global_mutex); + + qemu_thread_get_self(&io_thread); } #endif /* CONFIG_KVM */ diff --git a/sysemu.h b/sysemu.h index 560210d..5cacb9e 100644 --- a/sysemu.h +++ b/sysemu.h @@ -48,6 +48,7 @@ int qemu_reset_requested_get(void); int qemu_shutdown_requested(void); int qemu_reset_requested(void); int qemu_powerdown_requested(void); +int qemu_vmstop_requested(void); void qemu_system_killed(int signal, pid_t pid); void qemu_kill_report(void); extern qemu_irq qemu_system_powerdown; diff --git a/vl.c b/vl.c index 2587aae..6b5877b 100644 --- a/vl.c +++ b/vl.c @@ -1225,7 +1225,7 @@ static int qemu_debug_requested(void) return r; } -static int qemu_vmstop_requested(void) +int qemu_vmstop_requested(void) { int r = vmstop_requested; vmstop_requested = 0; @@ -1273,10 +1273,6 @@ void qemu_system_reset_request(void) } else { reset_requested = 1; } - if (cpu_single_env) { - cpu_single_env->stopped = 1; - cpu_exit(cpu_single_env); - } cpu_stop_current(); qemu_notify_event(); }