Skip to contentSkip to conversation

thread queue

GIT PULL New Juan Quintela 2 participants 15 messages Jan 17, 2013

lore
Share & tools
lore
#0 lore raw

This is the intersect of the paolo & me patches for migration thread,

Changes from 2 days ago:
- spelling check from Eric
- put the commit that patch refered from (Eric)
- drop the buffered rename at paolo request.

Please, pull.

Thanks, Juan.

The following changes since commit 47f4dac3fde809e3da4e60d9eb699f1d4b378249:

Merge remote-tracking branch 'kraxel/chardev.1' into staging (2013-01-16 15:20:05 -0600)

are available in the git repository at:

git://repo.or.cz/qemu/quintela.git thread.next

for you to fetch changes up to 6522773f88a2e37800f0bf7dc3632a14649f53c6:

migration: remove argument to qemu_savevm_state_cancel (2013-01-17 13:54:52 +0100)

----------------------------------------------------------------
Juan Quintela (7):
qemu-file: Only set last_error if it is not already set
migration: move beginning stage to the migration thread
migration: Add buffered_flush error handling
migration: move exit condition to migration thread
migration: unfold rest of migrate_fd_put_ready() into thread
migration: Only go to the iterate stage if there is anything to send
migration: remove argument to qemu_savevm_state_cancel

Paolo Bonzini (6):
Unlock ramlist lock also in error case Protect migration_bitmap_sync() with the ramlist lock use XFER_LIMIT_RATIO consistently
migration: make function static
migration: remove double call to migrate_fd_close
migration: fix off-by-one in buffered_rate_limit

 arch_init.c                   |   6 +-
 include/migration/migration.h |   3 -
 include/sysemu/sysemu.h       |   2 +-
 migration.c                   | 149 ++++++++++++++++++++----------------------
 savevm.c                      |  12 ++--
 5 files changed, 81 insertions(+), 91 deletions(-)
#1 lore raw

PATCH 1/13 Unlock ramlist lock also in error case

From: Paolo Bonzini <[email protected]>

---
 arch_init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch_init.c +2 -1
index 86f8544..8c833b6 100644
@@ -642,12 +642,13 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
         i++;
     }
 
+    qemu_mutex_unlock_ramlist();
+
     if (ret < 0) {
         bytes_transferred += total_sent;
         return ret;
     }
 
-    qemu_mutex_unlock_ramlist();
     qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
     total_sent += 8;
     bytes_transferred += total_sent;
Signature · 1 line
1.8.1
#2 lore raw

PATCH 2/13 Protect migration_bitmap_sync() with the ramlist lock

In reply to Juan Quintela

From: Paolo Bonzini <[email protected]>

---
 arch_init.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch_init.c +1 -2
index 8c833b6..dada6de 100644
@@ -658,9 +658,8 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
 
 static int ram_save_complete(QEMUFile *f, void *opaque)
 {
-    migration_bitmap_sync();
-
     qemu_mutex_lock_ramlist();
+    migration_bitmap_sync();
 
     /* try transferring iterative blocks of memory */
 
Signature · 1 line
1.8.1
#3 lore raw

PATCH 3/13 use XFER_LIMIT_RATIO consistently

In reply to Juan Quintela

From: Paolo Bonzini <[email protected]>

commit 5b4e1eb769eee892b44d3f6b2369b05196442f59

missed this use.

---
 migration.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration.c +1 -1
index c69e864..d6ec3e8 100644
@@ -650,7 +650,7 @@ static int64_t buffered_set_rate_limit(void *opaque, int64_t new_rate)
         new_rate = SIZE_MAX;
     }
 
-    s->xfer_limit = new_rate / 10;
+    s->xfer_limit = new_rate / XFER_LIMIT_RATIO;
 
 out:
     return s->xfer_limit;
Signature · 1 line
1.8.1
#4 lore raw

PATCH 4/13 migration: make function static

In reply to Juan Quintela

From: Paolo Bonzini <[email protected]>

---
 include/migration/migration.h | 2 --
 migration.c                   | 4 ++--
 2 files changed, 2 insertions(+), 4 deletions(-)
include/migration/migration.h +0 -2
index 2d5b630..95261c1 100644
@@ -87,8 +87,6 @@ void migrate_fd_error(MigrationState *s);
 
 void migrate_fd_connect(MigrationState *s);
 
-ssize_t migrate_fd_put_buffer(MigrationState *s, const void *data,
-                              size_t size);
 int migrate_fd_close(MigrationState *s);
 
 void add_migration_state_change_notifier(Notifier *notify);
migration.c +2 -2
index d6ec3e8..1f4c6ee 100644
@@ -302,8 +302,8 @@ static void migrate_fd_completed(MigrationState *s)
     notifier_list_notify(&migration_state_notifiers, s);
 }
 
-ssize_t migrate_fd_put_buffer(MigrationState *s, const void *data,
-                              size_t size)
+static ssize_t migrate_fd_put_buffer(MigrationState *s, const void *data,
+                                     size_t size)
 {
     ssize_t ret;
 
Signature · 1 line
1.8.1
#5 lore raw

PATCH 5/13 migration: remove double call to migrate_fd_close

In reply to Juan Quintela

From: Paolo Bonzini <[email protected]>

The call in buffered_close is enough, because buffered_close is called already by migrate_fd_cleanup.

---
 migration.c | 1 -
 1 file changed, 1 deletion(-)
migration.c +0 -1
index 1f4c6ee..5513dde 100644
@@ -605,7 +605,6 @@ static int buffered_close(void *opaque)
     if (ret >= 0) {
         ret = ret2;
     }
-    ret = migrate_fd_close(s);
     s->complete = true;
     return ret;
 }
Signature · 1 line
1.8.1
#6 lore raw

PATCH 6/13 migration: fix off-by-one in buffered_rate_limit

In reply to Juan Quintela

From: Paolo Bonzini <[email protected]>

---
 migration.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration.c +1 -1
index 5513dde..380f3cb 100644
@@ -632,7 +632,7 @@ static int buffered_rate_limit(void *opaque)
         return ret;
     }
 
-    if (s->bytes_xfer > s->xfer_limit) {
+    if (s->bytes_xfer >= s->xfer_limit) {
         return 1;
     }
 
Signature · 1 line
1.8.1
#7 lore raw

PATCH 7/13 qemu-file: Only set last_error if it is not already set

In reply to Juan Quintela
---
 savevm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
savevm.c +3 -1
index 4e970ca..611e997 100644
@@ -419,7 +419,9 @@ int qemu_file_get_error(QEMUFile *f)
 
 static void qemu_file_set_error(QEMUFile *f, int ret)
 {
-    f->last_error = ret;
+    if (f->last_error == 0) {
+        f->last_error = ret;
+    }
 }
 
 /** Flushes QEMUFile buffer
Signature · 1 line
1.8.1
#8 lore raw

PATCH 8/13 migration: move beginning stage to the migration thread

In reply to Juan Quintela
---
 include/migration/migration.h |  1 -
 migration.c                   | 28 +++++++++++++++-------------
 2 files changed, 15 insertions(+), 14 deletions(-)
include/migration/migration.h +0 -1
index 95261c1..a8c9639 100644
@@ -54,7 +54,6 @@ struct MigrationState
     bool enabled_capabilities[MIGRATION_CAPABILITY_MAX];
     int64_t xbzrle_cache_size;
     bool complete;
-    bool first_time;
 };
 
 void process_incoming_migration(QEMUFile *f);
migration.c +15 -13
index 380f3cb..7ae1d93 100644
@@ -674,17 +674,6 @@ static bool migrate_fd_put_ready(MigrationState *s, uint64_t max_size)
         qemu_mutex_unlock_iothread();
         return false;
     }
-    if (s->first_time) {
-        s->first_time = false;
-        DPRINTF("beginning savevm\n");
-        ret = qemu_savevm_state_begin(s->file, &s->params);
-        if (ret < 0) {
-            DPRINTF("failed, %d\n", ret);
-            migrate_fd_error(s);
-            qemu_mutex_unlock_iothread();
-            return false;
-        }
-    }
 
     DPRINTF("iterate\n");
     pending_size = qemu_savevm_state_pending(s->file, max_size);
@@ -733,6 +722,17 @@ static void *buffered_file_thread(void *opaque)
     int64_t initial_time = qemu_get_clock_ms(rt_clock);
     int64_t max_size = 0;
     bool last_round = false;
+    int ret;
+
+    qemu_mutex_lock_iothread();
+    DPRINTF("beginning savevm\n");
+    ret = qemu_savevm_state_begin(s->file, &s->params);
+    if (ret < 0) {
+        DPRINTF("failed, %d\n", ret);
+        qemu_mutex_unlock_iothread();
+        goto out;
+    }
+    qemu_mutex_unlock_iothread();
 
     while (true) {
         int64_t current_time = qemu_get_clock_ms(rt_clock);
@@ -768,6 +768,10 @@ static void *buffered_file_thread(void *opaque)
         }
     }
 
+out:
+    if (ret < 0) {
+        migrate_fd_error(s);
+    }
     g_free(s->buffer);
     return NULL;
 }
@@ -789,8 +793,6 @@ void migrate_fd_connect(MigrationState *s)
     s->buffer_size = 0;
     s->buffer_capacity = 0;
 
-    s->first_time = true;
-
     s->xfer_limit = s->bandwidth_limit / XFER_LIMIT_RATIO;
     s->complete = false;
 
Signature · 1 line
1.8.1
#9 lore raw

PATCH 9/13 migration: Add buffered_flush error handling

In reply to Juan Quintela

Now that we have error handling we can do proper handling of buffered_flush().

---
 migration.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
migration.c +2 -1
index 7ae1d93..17eb27d 100644
@@ -757,7 +757,8 @@ static void *buffered_file_thread(void *opaque)
             /* usleep expects microseconds */
             g_usleep((initial_time + BUFFER_DELAY - current_time)*1000);
         }
-        if (buffered_flush(s) < 0) {
+        ret = buffered_flush(s);
+        if (ret < 0) {
             break;
         }
 
Signature · 1 line
1.8.1
#10 lore raw

PATCH 10/13 migration: move exit condition to migration thread

In reply to Juan Quintela
---
 migration.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
migration.c +8 -6
index 17eb27d..651edd5 100644
@@ -669,12 +669,6 @@ static bool migrate_fd_put_ready(MigrationState *s, uint64_t max_size)
     bool last_round = false;
 
     qemu_mutex_lock_iothread();
-    if (s->state != MIG_STATE_ACTIVE) {
-        DPRINTF("put_ready returning because of non-active state\n");
-        qemu_mutex_unlock_iothread();
-        return false;
-    }
-
     DPRINTF("iterate\n");
     pending_size = qemu_savevm_state_pending(s->file, max_size);
     DPRINTF("pending size %lu max %lu\n", pending_size, max_size);
@@ -737,9 +731,17 @@ static void *buffered_file_thread(void *opaque)
     while (true) {
         int64_t current_time = qemu_get_clock_ms(rt_clock);
 
+        qemu_mutex_lock_iothread();
+        if (s->state != MIG_STATE_ACTIVE) {
+            DPRINTF("put_ready returning because of non-active state\n");
+            qemu_mutex_unlock_iothread();
+            break;
+        }
         if (s->complete) {
+            qemu_mutex_unlock_iothread();
             break;
         }
+        qemu_mutex_unlock_iothread();
         if (current_time >= initial_time + BUFFER_DELAY) {
             uint64_t transferred_bytes = s->bytes_xfer;
             uint64_t time_spent = current_time - initial_time;
Signature · 1 line
1.8.1
#11 lore raw

PATCH 11/13 migration: unfold rest of migrate_fd_put_ready() into thread

In reply to Juan Quintela

This will allow us finer control in next patches.

---
 migration.c | 95 ++++++++++++++++++++++++++-----------------------------------
 1 file changed, 41 insertions(+), 54 deletions(-)
migration.c +41 -54
index 651edd5..6d3aeed 100644
@@ -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:
Signature · 1 line
1.8.1
#12 lore raw

PATCH 12/13 migration: Only go to the iterate stage if there is anything to send

In reply to Juan Quintela
---
 migration.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
migration.c +1 -1
index 6d3aeed..fe1a103 100644
@@ -698,7 +698,7 @@ static void *buffered_file_thread(void *opaque)
             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) {
+            if (pending_size && pending_size >= max_size) {
                 ret = qemu_savevm_state_iterate(s->file);
                 if (ret < 0) {
                     qemu_mutex_unlock_iothread();
Signature · 1 line
1.8.1
#13 lore raw

PATCH 13/13 migration: remove argument to qemu_savevm_state_cancel

In reply to Juan Quintela
---
 include/sysemu/sysemu.h | 2 +-
 migration.c             | 2 +-
 savevm.c                | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
include/sysemu/sysemu.h +1 -1
index c07d4ee..d65a9f1 100644
@@ -77,7 +77,7 @@ int qemu_savevm_state_begin(QEMUFile *f,
                             const MigrationParams *params);
 int qemu_savevm_state_iterate(QEMUFile *f);
 int qemu_savevm_state_complete(QEMUFile *f);
-void qemu_savevm_state_cancel(QEMUFile *f);
+void qemu_savevm_state_cancel(void);
 uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size);
 int qemu_loadvm_state(QEMUFile *f);
 
migration.c +1 -1
index fe1a103..77c1971 100644
@@ -330,7 +330,7 @@ static void migrate_fd_cancel(MigrationState *s)
 
     s->state = MIG_STATE_CANCELLED;
     notifier_list_notify(&migration_state_notifiers, s);
-    qemu_savevm_state_cancel(s->file);
+    qemu_savevm_state_cancel();
 
     migrate_fd_cleanup(s);
 }
savevm.c +4 -4
index 611e997..913a623 100644
@@ -1590,13 +1590,13 @@ int qemu_savevm_state_begin(QEMUFile *f,
 
         ret = se->ops->save_live_setup(f, se->opaque);
         if (ret < 0) {
-            qemu_savevm_state_cancel(f);
+            qemu_savevm_state_cancel();
             return ret;
         }
     }
     ret = qemu_file_get_error(f);
     if (ret != 0) {
-        qemu_savevm_state_cancel(f);
+        qemu_savevm_state_cancel();
     }
 
     return ret;
@@ -1647,7 +1647,7 @@ int qemu_savevm_state_iterate(QEMUFile *f)
     }
     ret = qemu_file_get_error(f);
     if (ret != 0) {
-        qemu_savevm_state_cancel(f);
+        qemu_savevm_state_cancel();
     }
     return ret;
 }
@@ -1727,7 +1727,7 @@ uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size)
     return ret;
 }
 
-void qemu_savevm_state_cancel(QEMUFile *f)
+void qemu_savevm_state_cancel(void)
 {
     SaveStateEntry *se;
 
Signature · 1 line
1.8.1
#14 lore raw
In reply to Juan Quintela
Quoted 8 lines · Juan Quintela

This is the intersect of the paolo & me patches for migration thread,

Changes from 2 days ago:
- spelling check from Eric
- put the commit that patch refered from (Eric)
- drop the buffered rename at paolo request.

Please, pull.

If these were just posted two days ago, it's too early to do a pull request. Give people time to review the series.

Regards,

Anthony Liguori

Quoted 40 lines

Thanks, Juan.

The following changes since commit 47f4dac3fde809e3da4e60d9eb699f1d4b378249:

Merge remote-tracking branch 'kraxel/chardev.1' into staging (2013-01-16 15:20:05 -0600)

are available in the git repository at:

git://repo.or.cz/qemu/quintela.git thread.next

for you to fetch changes up to 6522773f88a2e37800f0bf7dc3632a14649f53c6:

migration: remove argument to qemu_savevm_state_cancel (2013-01-17 13:54:52 +0100)

----------------------------------------------------------------
Juan Quintela (7):
qemu-file: Only set last_error if it is not already set
migration: move beginning stage to the migration thread
migration: Add buffered_flush error handling
migration: move exit condition to migration thread
migration: unfold rest of migrate_fd_put_ready() into thread
migration: Only go to the iterate stage if there is anything to send
migration: remove argument to qemu_savevm_state_cancel

Paolo Bonzini (6):
Unlock ramlist lock also in error case Protect migration_bitmap_sync() with the ramlist lock use XFER_LIMIT_RATIO consistently
migration: make function static
migration: remove double call to migrate_fd_close
migration: fix off-by-one in buffered_rate_limit

 arch_init.c                   |   6 +-
 include/migration/migration.h |   3 -
 include/sysemu/sysemu.h       |   2 +-
 migration.c                   | 149 ++++++++++++++++++++----------------------
 savevm.c                      |  12 ++--
 5 files changed, 81 insertions(+), 91 deletions(-)