From patchwork Wed Aug 3 15:17:21 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 108296 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 96003B71D4 for ; Thu, 4 Aug 2011 02:03:28 +1000 (EST) Received: from localhost ([::1]:37723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QodE3-0000bq-NR for incoming@patchwork.ozlabs.org; Wed, 03 Aug 2011 11:19:15 -0400 Received: from eggs.gnu.org ([140.186.70.92]:39728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QodDk-0005mj-HE for qemu-devel@nongnu.org; Wed, 03 Aug 2011 11:19:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QodD1-0006gU-BM for qemu-devel@nongnu.org; Wed, 03 Aug 2011 11:18:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5074) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QodD0-0006cC-WA for qemu-devel@nongnu.org; Wed, 03 Aug 2011 11:18:11 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p73FHnEx008102 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 3 Aug 2011 11:17:49 -0400 Received: from localhost (ovpn-113-124.phx2.redhat.com [10.3.113.124]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p73FHlpV004273; Wed, 3 Aug 2011 11:17:48 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 3 Aug 2011 12:17:21 -0300 Message-Id: <1312384643-581-6-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1312384643-581-1-git-send-email-lcapitulino@redhat.com> References: <1312384643-581-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: blauwirbel@gmail.com, amit.shah@redhat.com, aliguori@us.ibm.com, jan.kiszka@web.de, avi@redhat.com Subject: [Qemu-devel] [PATCH 5/7] Drop the vm_running global variable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use qemu_is_running() instead, which is introduced by this commit and is part of the QemuState API. Signed-off-by: Luiz Capitulino --- cpus.c | 9 ++++----- gdbstub.c | 4 ++-- hw/etraxfs_dma.c | 2 +- hw/kvmclock.c | 2 +- hw/virtio.c | 2 +- migration.c | 2 +- monitor.c | 4 ++-- qemu-timer.c | 8 ++++---- savevm.c | 4 ++-- sysemu.h | 2 +- target-i386/kvm.c | 2 +- ui/sdl.c | 6 +++--- vl.c | 9 ++++++--- xen-all.c | 2 +- 14 files changed, 30 insertions(+), 28 deletions(-) diff --git a/cpus.c b/cpus.c index 48e6ca1..65ea503 100644 --- a/cpus.c +++ b/cpus.c @@ -115,14 +115,13 @@ void cpu_synchronize_all_post_init(void) int cpu_is_stopped(CPUState *env) { - return !vm_running || env->stopped; + return !qemu_is_running() || env->stopped; } static void do_vm_stop(QemuState state) { - if (vm_running) { + if (qemu_is_running()) { cpu_disable_ticks(); - vm_running = 0; pause_all_vcpus(); qemu_state_set(state); vm_state_notify(0, state); @@ -137,7 +136,7 @@ static int cpu_can_run(CPUState *env) if (env->stop) { return 0; } - if (env->stopped || !vm_running) { + if (env->stopped || !qemu_is_running()) { return 0; } return 1; @@ -148,7 +147,7 @@ static bool cpu_thread_is_idle(CPUState *env) if (env->stop || env->queued_work_first) { return false; } - if (env->stopped || !vm_running) { + if (env->stopped || !qemu_is_running()) { return true; } if (!env->halted || qemu_cpu_has_work(env) || diff --git a/gdbstub.c b/gdbstub.c index ae57d6a..63ba0a4 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -2428,7 +2428,7 @@ static void gdb_read_byte(GDBState *s, int ch) if (ch != '$') return; } - if (vm_running) { + if (qemu_is_running()) { /* when the CPU is running, we cannot do anything except stop it when receiving a char */ vm_stop(QSTATE_PAUSED); @@ -2733,7 +2733,7 @@ static int gdb_monitor_write(CharDriverState *chr, const uint8_t *buf, int len) #ifndef _WIN32 static void gdb_sigterm_handler(int signal) { - if (vm_running) { + if (qemu_is_running()) { vm_stop(QSTATE_PAUSED); } } diff --git a/hw/etraxfs_dma.c b/hw/etraxfs_dma.c index c205ec1..d9bf64a 100644 --- a/hw/etraxfs_dma.c +++ b/hw/etraxfs_dma.c @@ -732,7 +732,7 @@ static void DMA_run(void *opaque) struct fs_dma_ctrl *etraxfs_dmac = opaque; int p = 1; - if (vm_running) + if (qemu_is_running()) p = etraxfs_dmac_run(etraxfs_dmac); if (p) diff --git a/hw/kvmclock.c b/hw/kvmclock.c index de5a655..ebf9da4 100644 --- a/hw/kvmclock.c +++ b/hw/kvmclock.c @@ -46,7 +46,7 @@ static void kvmclock_pre_save(void *opaque) * it on next vmsave (which would return a different value). Will be reset * when the VM is continued. */ - s->clock_valid = !vm_running; + s->clock_valid = !qemu_is_running(); } static int kvmclock_post_load(void *opaque, int version_id) diff --git a/hw/virtio.c b/hw/virtio.c index 7293db0..0d9f58a 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -869,7 +869,7 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id, vdev->queue_sel = 0; vdev->config_vector = VIRTIO_NO_VECTOR; vdev->vq = qemu_mallocz(sizeof(VirtQueue) * VIRTIO_PCI_QUEUE_MAX); - vdev->vm_running = vm_running; + vdev->vm_running = qemu_is_running(); for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) { vdev->vq[i].vector = VIRTIO_NO_VECTOR; vdev->vq[i].vdev = vdev; diff --git a/migration.c b/migration.c index 73e9bd6..a073be8 100644 --- a/migration.c +++ b/migration.c @@ -376,7 +376,7 @@ void migrate_fd_put_ready(void *opaque) DPRINTF("iterate\n"); if (qemu_savevm_state_iterate(s->mon, s->file) == 1) { int state; - int old_vm_running = vm_running; + int old_vm_running = qemu_is_running(); DPRINTF("done iterating\n"); vm_stop(QSTATE_PREMIGRATE); diff --git a/monitor.c b/monitor.c index 05c5936..3fa2cf7 100644 --- a/monitor.c +++ b/monitor.c @@ -2618,7 +2618,7 @@ static void do_info_status_print(Monitor *mon, const QObject *data) static void do_info_status(Monitor *mon, QObject **ret_data) { *ret_data = qobject_from_jsonf("{ 'running': %i, 'singlestep': %i }", - vm_running, singlestep); + qemu_is_running(), singlestep); } static qemu_acl *find_acl(Monitor *mon, const char *name) @@ -2811,7 +2811,7 @@ static int do_closefd(Monitor *mon, const QDict *qdict, QObject **ret_data) static void do_loadvm(Monitor *mon, const QDict *qdict) { - int saved_vm_running = vm_running; + int saved_vm_running = qemu_is_running(); const char *name = qdict_get_str(qdict, "name"); vm_stop(QSTATE_RESTVM); diff --git a/qemu-timer.c b/qemu-timer.c index 5dbaaa3..319f197 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -246,7 +246,7 @@ static void icount_adjust(void) int64_t delta; static int64_t last_delta; /* If the VM is not running, then do nothing. */ - if (!vm_running) + if (!qemu_is_running()) return; cur_time = cpu_get_clock(); @@ -404,7 +404,7 @@ static void icount_warp_rt(void *opaque) return; } - if (vm_running) { + if (qemu_is_running()) { int64_t clock = qemu_get_clock_ns(rt_clock); int64_t warp_delta = clock - vm_clock_warp_start; if (use_icount == 1) { @@ -728,7 +728,7 @@ void qemu_run_all_timers(void) } /* vm time timers */ - if (vm_running) { + if (qemu_is_running()) { qemu_run_timers(vm_clock); } @@ -1182,7 +1182,7 @@ int qemu_calculate_timeout(void) #ifndef CONFIG_IOTHREAD int timeout; - if (!vm_running) + if (!qemu_is_running()) timeout = 5000; else { /* XXX: use timeout computed from timers */ diff --git a/savevm.c b/savevm.c index d8db493..fbfcdfa 100644 --- a/savevm.c +++ b/savevm.c @@ -1602,7 +1602,7 @@ static int qemu_savevm_state(Monitor *mon, QEMUFile *f) int saved_vm_running; int ret; - saved_vm_running = vm_running; + saved_vm_running = qemu_is_running(); vm_stop(QSTATE_SAVEVM); if (qemu_savevm_state_blocked(mon)) { @@ -1931,7 +1931,7 @@ void do_savevm(Monitor *mon, const QDict *qdict) return; } - saved_vm_running = vm_running; + saved_vm_running = qemu_is_running(); vm_stop(QSTATE_SAVEVM); memset(sn, 0, sizeof(*sn)); diff --git a/sysemu.h b/sysemu.h index 32c9abb..46079ab 100644 --- a/sysemu.h +++ b/sysemu.h @@ -31,12 +31,12 @@ typedef enum { extern const char *bios_name; -extern int vm_running; extern const char *qemu_name; extern uint8_t qemu_uuid[]; int qemu_uuid_parse(const char *str, uint8_t *uuid); #define UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" +int qemu_is_running(void); QemuState qemu_state_get(void); void qemu_state_set(QemuState state); typedef struct vm_change_state_entry VMChangeStateEntry; diff --git a/target-i386/kvm.c b/target-i386/kvm.c index c88cd14..531589c 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -1115,7 +1115,7 @@ static int kvm_get_msrs(CPUState *env) if (!env->tsc_valid) { msrs[n++].index = MSR_IA32_TSC; - env->tsc_valid = !vm_running; + env->tsc_valid = !qemu_is_running(); } #ifdef TARGET_X86_64 diff --git a/ui/sdl.c b/ui/sdl.c index 6dbc5cb..ba2363c 100644 --- a/ui/sdl.c +++ b/ui/sdl.c @@ -407,7 +407,7 @@ static void sdl_update_caption(void) char icon_title[1024]; const char *status = ""; - if (!vm_running) + if (!qemu_is_running()) status = " [Stopped]"; else if (gui_grab) { if (alt_grab) @@ -545,8 +545,8 @@ static void sdl_refresh(DisplayState *ds) int mod_state; int buttonstate = SDL_GetMouseState(NULL, NULL); - if (last_vm_running != vm_running) { - last_vm_running = vm_running; + if (last_vm_running != qemu_is_running()) { + last_vm_running = qemu_is_running(); sdl_update_caption(); } diff --git a/vl.c b/vl.c index c2ab7ce..65cf4a5 100644 --- a/vl.c +++ b/vl.c @@ -183,7 +183,6 @@ int mem_prealloc = 0; /* force preallocation of physical target memory */ #endif int nb_nics; NICInfo nd_table[MAX_NICS]; -int vm_running; int autostart; static int rtc_utc = 1; static int rtc_date_offset = -1; /* -1 means no change */ @@ -334,6 +333,11 @@ void qemu_state_set(QemuState state) qemu_current_state = state; } +int qemu_is_running(void) +{ + return qemu_current_state == QSTATE_RUNNING; +} + /***********************************************************/ /* real time host monotonic timer */ @@ -1170,9 +1174,8 @@ void vm_state_notify(int running, QemuState state) void vm_start(void) { - if (!vm_running) { + if (!qemu_is_running()) { cpu_enable_ticks(); - vm_running = 1; qemu_state_set(QSTATE_RUNNING); vm_state_notify(1, QSTATE_RUNNING); resume_all_vcpus(); diff --git a/xen-all.c b/xen-all.c index 5d2bc4c..fbbdf77 100644 --- a/xen-all.c +++ b/xen-all.c @@ -736,7 +736,7 @@ static void cpu_handle_ioreq(void *opaque) * guest resumes and does a hlt with interrupts disabled which * causes Xen to powerdown the domain. */ - if (vm_running) { + if (qemu_is_running()) { if (qemu_shutdown_requested_get()) { destroy_hvm_domain(); }