From patchwork Tue Jul 21 22:13:08 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 36639 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6LMDToA002829 for ; Tue, 21 Jul 2009 22:13:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756392AbZGUWNR (ORCPT ); Tue, 21 Jul 2009 18:13:17 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756388AbZGUWNR (ORCPT ); Tue, 21 Jul 2009 18:13:17 -0400 Received: from mx2.redhat.com ([66.187.237.31]:54765 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755371AbZGUWNO (ORCPT ); Tue, 21 Jul 2009 18:13:14 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n6LMDFl1023920 for ; Tue, 21 Jul 2009 18:13:15 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n6LMDE6Y008864; Tue, 21 Jul 2009 18:13:14 -0400 Received: from localhost.localdomain (virtlab1.virt.bos.redhat.com [10.16.72.21]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n6LMDC97012787; Tue, 21 Jul 2009 18:13:13 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com Subject: [PATCH v2 2/6] reuse env stop and stopped states Date: Tue, 21 Jul 2009 18:13:08 -0400 Message-Id: <1248214392-12533-3-git-send-email-glommer@redhat.com> In-Reply-To: <1248214392-12533-2-git-send-email-glommer@redhat.com> References: <1248214392-12533-1-git-send-email-glommer@redhat.com> <1248214392-12533-2-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org qemu CPUState already provides "stop" and "stopped" states. And they mean exactly that. There is no need for us to provide our own. Signed-off-by: Glauber Costa --- cpu-defs.h | 2 -- qemu-kvm.c | 30 ++++++++++++------------------ vl.c | 2 +- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/cpu-defs.h b/cpu-defs.h index 7570096..fce366f 100644 --- a/cpu-defs.h +++ b/cpu-defs.h @@ -142,8 +142,6 @@ struct qemu_work_item; struct KVMCPUState { pthread_t thread; int signalled; - int stop; - int stopped; int created; void *vcpu_ctx; struct qemu_work_item *queued_work_first, *queued_work_last; diff --git a/qemu-kvm.c b/qemu-kvm.c index 0f5f14f..8eeace4 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -91,7 +91,7 @@ static int kvm_debug(void *opaque, void *data, if (handle) { kvm_debug_cpu_requested = env; - env->kvm_cpu_state.stopped = 1; + env->stopped = 1; } return handle; } @@ -977,7 +977,7 @@ int handle_halt(kvm_vcpu_context_t vcpu) int handle_shutdown(kvm_context_t kvm, CPUState *env) { /* stop the current vcpu from going back to guest mode */ - env->kvm_cpu_state.stopped = 1; + env->stopped = 1; qemu_system_reset_request(); return 1; @@ -1815,7 +1815,7 @@ int kvm_cpu_exec(CPUState *env) static int is_cpu_stopped(CPUState *env) { - return !vm_running || env->kvm_cpu_state.stopped; + return !vm_running || env->stopped; } static void flush_queued_work(CPUState *env) @@ -1861,9 +1861,9 @@ static void kvm_main_loop_wait(CPUState *env, int timeout) cpu_single_env = env; flush_queued_work(env); - if (env->kvm_cpu_state.stop) { - env->kvm_cpu_state.stop = 0; - env->kvm_cpu_state.stopped = 1; + if (env->stop) { + env->stop = 0; + env->stopped = 1; pthread_cond_signal(&qemu_pause_cond); } @@ -1875,7 +1875,7 @@ static int all_threads_paused(void) CPUState *penv = first_cpu; while (penv) { - if (penv->kvm_cpu_state.stop) + if (penv->stop) return 0; penv = (CPUState *)penv->next_cpu; } @@ -1889,11 +1889,11 @@ static void pause_all_threads(void) while (penv) { if (penv != cpu_single_env) { - penv->kvm_cpu_state.stop = 1; + penv->stop = 1; pthread_kill(penv->kvm_cpu_state.thread, SIG_IPI); } else { - penv->kvm_cpu_state.stop = 0; - penv->kvm_cpu_state.stopped = 1; + penv->stop = 0; + penv->stopped = 1; cpu_exit(penv); } penv = (CPUState *)penv->next_cpu; @@ -1910,8 +1910,8 @@ static void resume_all_threads(void) assert(!cpu_single_env); while (penv) { - penv->kvm_cpu_state.stop = 0; - penv->kvm_cpu_state.stopped = 0; + penv->stop = 0; + penv->stopped = 0; pthread_kill(penv->kvm_cpu_state.thread, SIG_IPI); penv = (CPUState *)penv->next_cpu; } @@ -2676,12 +2676,6 @@ int kvm_log_stop(target_phys_addr_t phys_addr, target_phys_addr_t len) return 0; } -void qemu_kvm_cpu_stop(CPUState *env) -{ - if (kvm_enabled()) - env->kvm_cpu_state.stopped = 1; -} - int kvm_set_boot_cpu_id(uint32_t id) { return kvm_set_boot_vcpu_id(kvm_context, id); diff --git a/vl.c b/vl.c index b3df596..6ef7690 100644 --- a/vl.c +++ b/vl.c @@ -3553,7 +3553,7 @@ void qemu_system_reset_request(void) reset_requested = 1; } if (cpu_single_env) { - qemu_kvm_cpu_stop(cpu_single_env); + cpu_single_env->stopped = 1; } qemu_notify_event(); }