qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: kwolf@redhat.com, jan.kiszka@siemens.com, qemu-devel@nongnu.org,
	armbru@redhat.com, avi@redhat.com, amit.shah@redhat.com
Subject: Re: [Qemu-devel] [PATCH 5/8] Drop the vm_running global variable
Date: Sun, 14 Aug 2011 11:43:06 -0500	[thread overview]
Message-ID: <4E47FB1A.7060805@codemonkey.ws> (raw)
In-Reply-To: <1313008408-23161-6-git-send-email-lcapitulino@redhat.com>

On 08/10/2011 03:33 PM, Luiz Capitulino wrote:
> Use vm_is_running() instead, which is introduced by this commit and
> is part of the RunState API.
>
> Signed-off-by: Luiz Capitulino<lcapitulino@redhat.com>
> ---
>   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 e74b5fc..e1cbc6b 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 !vm_is_running() || env->stopped;

Maybe we should have:

bool runstate_is_running();

?

Regards,

Anthony Liguori

>   }
>
>   static void do_vm_stop(RunState state)
>   {
> -    if (vm_running) {
> +    if (vm_is_running()) {
>           cpu_disable_ticks();
> -        vm_running = 0;
>           pause_all_vcpus();
>           runstate_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 || !vm_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 || !vm_is_running()) {
>           return true;
>       }
>       if (!env->halted || qemu_cpu_has_work(env) ||
> diff --git a/gdbstub.c b/gdbstub.c
> index 4aad1a6..e4415fc 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 (vm_is_running()) {
>           /* when the CPU is running, we cannot do anything except stop
>              it when receiving a char */
>           vm_stop(RSTATE_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 (vm_is_running()) {
>           vm_stop(RSTATE_PAUSED);
>       }
>   }
> diff --git a/hw/etraxfs_dma.c b/hw/etraxfs_dma.c
> index c205ec1..b265f5a 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 (vm_is_running())
>           p = etraxfs_dmac_run(etraxfs_dmac);
>
>       if (p)
> diff --git a/hw/kvmclock.c b/hw/kvmclock.c
> index 88961be..c31850a 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 = !vm_is_running();
>   }
>
>   static int kvmclock_post_load(void *opaque, int version_id)
> diff --git a/hw/virtio.c b/hw/virtio.c
> index ae0c53e..c443c6a 100644
> --- a/hw/virtio.c
> +++ b/hw/virtio.c
> @@ -870,7 +870,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 = vm_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 a1a955d..622b6a6 100644
> --- a/migration.c
> +++ b/migration.c
> @@ -372,7 +372,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 = vm_is_running();
>
>           DPRINTF("done iterating\n");
>           vm_stop(RSTATE_PRE_MIGRATE);
> diff --git a/monitor.c b/monitor.c
> index 72f26ab..3de862b 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);
> +                                    vm_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  = vm_is_running();
>       const char *name = qdict_get_str(qdict, "name");
>
>       vm_stop(RSTATE_RESTORE);
> diff --git a/qemu-timer.c b/qemu-timer.c
> index f0e19b1..e79359a 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 (!vm_is_running())
>           return;
>
>       cur_time = cpu_get_clock();
> @@ -404,7 +404,7 @@ static void icount_warp_rt(void *opaque)
>           return;
>       }
>
> -    if (vm_running) {
> +    if (vm_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 (vm_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 (!vm_is_running())
>           timeout = 5000;
>       else {
>        /* XXX: use timeout computed from timers */
> diff --git a/savevm.c b/savevm.c
> index ac92a1a..87f9cfc 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 = vm_is_running();
>       vm_stop(RSTATE_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 = vm_is_running();
>       vm_stop(RSTATE_SAVEVM);
>
>       memset(sn, 0, sizeof(*sn));
> diff --git a/sysemu.h b/sysemu.h
> index 19c9ab6..9a8ea78 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 vm_is_running(void);
>   RunState runstate_get(void);
>   void runstate_set(RunState state);
>   typedef struct vm_change_state_entry VMChangeStateEntry;
> diff --git a/target-i386/kvm.c b/target-i386/kvm.c
> index 0672d10..c98e570 100644
> --- a/target-i386/kvm.c
> +++ b/target-i386/kvm.c
> @@ -1129,7 +1129,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 = !vm_is_running();
>       }
>
>   #ifdef TARGET_X86_64
> diff --git a/ui/sdl.c b/ui/sdl.c
> index 30cde86..4491d80 100644
> --- a/ui/sdl.c
> +++ b/ui/sdl.c
> @@ -409,7 +409,7 @@ static void sdl_update_caption(void)
>       char icon_title[1024];
>       const char *status = "";
>
> -    if (!vm_running)
> +    if (!vm_is_running())
>           status = " [Stopped]";
>       else if (gui_grab) {
>           if (alt_grab)
> @@ -851,8 +851,8 @@ static void sdl_refresh(DisplayState *ds)
>   {
>       SDL_Event ev1, *ev =&ev1;
>
> -    if (last_vm_running != vm_running) {
> -        last_vm_running = vm_running;
> +    if (last_vm_running != vm_is_running()) {
> +        last_vm_running = vm_is_running();
>           sdl_update_caption();
>       }
>
> diff --git a/vl.c b/vl.c
> index 9be0cfc..2b4cec2 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 */
> @@ -335,6 +334,11 @@ void runstate_set(RunState state)
>       current_run_state = state;
>   }
>
> +int vm_is_running(void)
> +{
> +    return current_run_state == RSTATE_RUNNING;
> +}
> +
>   /***********************************************************/
>   /* real time host monotonic timer */
>
> @@ -1171,9 +1175,8 @@ void vm_state_notify(int running, RunState state)
>
>   void vm_start(void)
>   {
> -    if (!vm_running) {
> +    if (!vm_is_running()) {
>           cpu_enable_ticks();
> -        vm_running = 1;
>           runstate_set(RSTATE_RUNNING);
>           vm_state_notify(1, RSTATE_RUNNING);
>           resume_all_vcpus();
> diff --git a/xen-all.c b/xen-all.c
> index ea97a19..544e001 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 (vm_is_running()) {
>               if (qemu_shutdown_requested_get()) {
>                   destroy_hvm_domain();
>               }

  reply	other threads:[~2011-08-14 18:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-10 20:33 [Qemu-devel] [PATCH v2 0/8]: Introduce the RunState type Luiz Capitulino
2011-08-10 20:33 ` [Qemu-devel] [PATCH 1/8] Move vm_state_notify() prototype from cpus.h to sysemu.h Luiz Capitulino
2011-08-10 20:33 ` [Qemu-devel] [PATCH 2/8] Replace the VMSTOP macros with a proper state type Luiz Capitulino
2011-08-10 20:33 ` [Qemu-devel] [PATCH 3/8] RunState: Add additional states Luiz Capitulino
2011-08-10 20:33 ` [Qemu-devel] [PATCH 4/8] Drop the incoming_expected global variable Luiz Capitulino
2011-08-14 16:42   ` Anthony Liguori
2011-08-10 20:33 ` [Qemu-devel] [PATCH 5/8] Drop the vm_running " Luiz Capitulino
2011-08-14 16:43   ` Anthony Liguori [this message]
2011-08-10 20:33 ` [Qemu-devel] [PATCH 6/8] Monitor: Don't allow cont on bad VM state Luiz Capitulino
2011-08-10 20:33 ` [Qemu-devel] [PATCH 7/8] QMP: query-status: Introduce 'status' key Luiz Capitulino
2011-08-14 16:44   ` Anthony Liguori
2011-08-10 20:33 ` [Qemu-devel] [PATCH 8/8] HMP: info status: Print the VM state Luiz Capitulino
2011-08-14 16:45 ` [Qemu-devel] [PATCH v2 0/8]: Introduce the RunState type Anthony Liguori
2011-08-15 21:44   ` Luiz Capitulino
  -- strict thread matches above, loose matches on Subject: below --
2011-09-01 18:12 [Qemu-devel] [PATCH v3 " Luiz Capitulino
2011-09-01 18:12 ` [Qemu-devel] [PATCH 5/8] Drop the vm_running global variable Luiz Capitulino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E47FB1A.7060805@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=amit.shah@redhat.com \
    --cc=armbru@redhat.com \
    --cc=avi@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).