From patchwork Mon Jul 20 23:10:14 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 36425 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 n6KNAXtg021907 for ; Mon, 20 Jul 2009 23:10:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754339AbZGTXKa (ORCPT ); Mon, 20 Jul 2009 19:10:30 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754338AbZGTXKa (ORCPT ); Mon, 20 Jul 2009 19:10:30 -0400 Received: from mx2.redhat.com ([66.187.237.31]:53383 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753838AbZGTXKU (ORCPT ); Mon, 20 Jul 2009 19:10:20 -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 n6KNAKx5029411 for ; Mon, 20 Jul 2009 19:10:20 -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 n6KNAJ6m002979; Mon, 20 Jul 2009 19:10:19 -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 n6KNAGkk028980; Mon, 20 Jul 2009 19:10:18 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com Subject: [PATCH 7/9] reuse env stop and stopped states Date: Mon, 20 Jul 2009 19:10:14 -0400 Message-Id: <1248131416-11272-8-git-send-email-glommer@redhat.com> In-Reply-To: <1248131416-11272-7-git-send-email-glommer@redhat.com> References: <1248131416-11272-1-git-send-email-glommer@redhat.com> <1248131416-11272-2-git-send-email-glommer@redhat.com> <1248131416-11272-3-git-send-email-glommer@redhat.com> <1248131416-11272-4-git-send-email-glommer@redhat.com> <1248131416-11272-5-git-send-email-glommer@redhat.com> <1248131416-11272-6-git-send-email-glommer@redhat.com> <1248131416-11272-7-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 58d5de2..6d556b8 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; } @@ -979,7 +979,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; @@ -1817,7 +1817,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) @@ -1863,9 +1863,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); } @@ -1877,7 +1877,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; } @@ -1891,11 +1891,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; @@ -1912,8 +1912,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; } @@ -2698,12 +2698,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 92ae881..32134a2 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(); }