qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com
Subject: [Qemu-devel] [PATCH 11/13] migration: unfold rest of migrate_fd_put_ready() into thread
Date: Thu, 17 Jan 2013 14:39:31 +0100	[thread overview]
Message-ID: <1358429973-9321-12-git-send-email-quintela@redhat.com> (raw)
In-Reply-To: <1358429973-9321-1-git-send-email-quintela@redhat.com>

This will allow us finer control in next patches.

Signed-off-by: Juan Quintela <quintela@redhat.com>

Reviewed-by: Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
---
 migration.c | 95 ++++++++++++++++++++++++++-----------------------------------
 1 file changed, 41 insertions(+), 54 deletions(-)

diff --git a/migration.c b/migration.c
index 651edd5..6d3aeed 100644
--- a/migration.c
+++ b/migration.c
@@ -662,54 +662,6 @@ static int64_t buffered_get_rate_limit(void *opaque)
     return s->xfer_limit;
 }

-static bool migrate_fd_put_ready(MigrationState *s, uint64_t max_size)
-{
-    int ret;
-    uint64_t pending_size;
-    bool last_round = false;
-
-    qemu_mutex_lock_iothread();
-    DPRINTF("iterate\n");
-    pending_size = qemu_savevm_state_pending(s->file, max_size);
-    DPRINTF("pending size %lu max %lu\n", pending_size, max_size);
-    if (pending_size >= max_size) {
-        ret = qemu_savevm_state_iterate(s->file);
-        if (ret < 0) {
-            migrate_fd_error(s);
-        }
-    } else {
-        int old_vm_running = runstate_is_running();
-        int64_t start_time, end_time;
-
-        DPRINTF("done iterating\n");
-        start_time = qemu_get_clock_ms(rt_clock);
-        qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
-        if (old_vm_running) {
-            vm_stop(RUN_STATE_FINISH_MIGRATE);
-        } else {
-            vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
-        }
-
-        if (qemu_savevm_state_complete(s->file) < 0) {
-            migrate_fd_error(s);
-        } else {
-            migrate_fd_completed(s);
-        }
-        end_time = qemu_get_clock_ms(rt_clock);
-        s->total_time = end_time - s->total_time;
-        s->downtime = end_time - start_time;
-        if (s->state != MIG_STATE_COMPLETED) {
-            if (old_vm_running) {
-                vm_start();
-            }
-        }
-        last_round = true;
-    }
-    qemu_mutex_unlock_iothread();
-
-    return last_round;
-}
-
 static void *buffered_file_thread(void *opaque)
 {
     MigrationState *s = opaque;
@@ -730,6 +682,7 @@ static void *buffered_file_thread(void *opaque)

     while (true) {
         int64_t current_time = qemu_get_clock_ms(rt_clock);
+        uint64_t pending_size;

         qemu_mutex_lock_iothread();
         if (s->state != MIG_STATE_ACTIVE) {
@@ -741,6 +694,46 @@ static void *buffered_file_thread(void *opaque)
             qemu_mutex_unlock_iothread();
             break;
         }
+        if (s->bytes_xfer < s->xfer_limit) {
+            DPRINTF("iterate\n");
+            pending_size = qemu_savevm_state_pending(s->file, max_size);
+            DPRINTF("pending size %lu max %lu\n", pending_size, max_size);
+            if (pending_size >= max_size) {
+                ret = qemu_savevm_state_iterate(s->file);
+                if (ret < 0) {
+                    qemu_mutex_unlock_iothread();
+                    break;
+                }
+            } else {
+                int old_vm_running = runstate_is_running();
+                int64_t start_time, end_time;
+
+                DPRINTF("done iterating\n");
+                start_time = qemu_get_clock_ms(rt_clock);
+                qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
+                if (old_vm_running) {
+                    vm_stop(RUN_STATE_FINISH_MIGRATE);
+                } else {
+                    vm_stop_force_state(RUN_STATE_FINISH_MIGRATE);
+                }
+                ret = qemu_savevm_state_complete(s->file);
+                if (ret < 0) {
+                    qemu_mutex_unlock_iothread();
+                    break;
+                } else {
+                    migrate_fd_completed(s);
+                }
+                end_time = qemu_get_clock_ms(rt_clock);
+                s->total_time = end_time - s->total_time;
+                s->downtime = end_time - start_time;
+                if (s->state != MIG_STATE_COMPLETED) {
+                    if (old_vm_running) {
+                        vm_start();
+                    }
+                }
+                last_round = true;
+            }
+        }
         qemu_mutex_unlock_iothread();
         if (current_time >= initial_time + BUFFER_DELAY) {
             uint64_t transferred_bytes = s->bytes_xfer;
@@ -763,12 +756,6 @@ static void *buffered_file_thread(void *opaque)
         if (ret < 0) {
             break;
         }
-
-        DPRINTF("file is ready\n");
-        if (s->bytes_xfer < s->xfer_limit) {
-            DPRINTF("notifying client\n");
-            last_round = migrate_fd_put_ready(s, max_size);
-        }
     }

 out:
-- 
1.8.1

  parent reply	other threads:[~2013-01-17 13:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-17 13:39 [Qemu-devel] [PULL 00/13] thread queue Juan Quintela
2013-01-17 13:39 ` [Qemu-devel] [PATCH 01/13] Unlock ramlist lock also in error case Juan Quintela
2013-01-17 13:39 ` [Qemu-devel] [PATCH 02/13] Protect migration_bitmap_sync() with the ramlist lock Juan Quintela
2013-01-17 13:39 ` [Qemu-devel] [PATCH 03/13] use XFER_LIMIT_RATIO consistently Juan Quintela
2013-01-17 13:39 ` [Qemu-devel] [PATCH 04/13] migration: make function static Juan Quintela
2013-01-17 13:39 ` [Qemu-devel] [PATCH 05/13] migration: remove double call to migrate_fd_close Juan Quintela
2013-01-17 13:39 ` [Qemu-devel] [PATCH 06/13] migration: fix off-by-one in buffered_rate_limit Juan Quintela
2013-01-17 13:39 ` [Qemu-devel] [PATCH 07/13] qemu-file: Only set last_error if it is not already set Juan Quintela
2013-01-17 13:39 ` [Qemu-devel] [PATCH 08/13] migration: move beginning stage to the migration thread Juan Quintela
2013-01-17 13:39 ` [Qemu-devel] [PATCH 09/13] migration: Add buffered_flush error handling Juan Quintela
2013-01-17 13:39 ` [Qemu-devel] [PATCH 10/13] migration: move exit condition to migration thread Juan Quintela
2013-01-17 13:39 ` Juan Quintela [this message]
2013-01-17 13:39 ` [Qemu-devel] [PATCH 12/13] migration: Only go to the iterate stage if there is anything to send Juan Quintela
2013-01-17 13:39 ` [Qemu-devel] [PATCH 13/13] migration: remove argument to qemu_savevm_state_cancel Juan Quintela
2013-01-17 15:22 ` [Qemu-devel] [PULL 00/13] thread queue Anthony Liguori

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=1358429973-9321-12-git-send-email-quintela@redhat.com \
    --to=quintela@redhat.com \
    --cc=aliguori@us.ibm.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).