Skip to contentSkip to conversation

migration: Optimization about wait-unplug migration state

PATCH In review Keqian Zhu 3 participants 5 messages Feb 4, 2020 – Feb 10, 2020

lore
Share & tools
lore

Keqian Zhu

author
#0 lore raw

PATCH 1/1 migration: Optimization about wait-unplug migration state

qemu_savevm_nr_failover_devices() is originally designed to get the number of failover devices, but it actually returns the number of "unplug-pending" failover devices now. Moreover, what drives migration state to wait-unplug should be the number of "unplug-pending" failover devices, not all failover devices.

We can also notice that qemu_savevm_state_guest_unplug_pending() and qemu_savevm_nr_failover_devices() is equivalent almost (from the code view). So the latter is incorrect semantically and useless, just delete it.

In the qemu_savevm_state_guest_unplug_pending(), once hit a unplug-pending failover device, then it can return true right now to save cpu time.

---
Cc: [email protected]
Cc: Juan Quintela <[email protected]>
Cc: "Dr. David Alan Gilbert" <[email protected]>

---
 migration/migration.c |  2 +-
 migration/savevm.c    | 24 +++---------------------
 migration/savevm.h    |  1 -
 3 files changed, 4 insertions(+), 23 deletions(-)
migration/migration.c +1 -1
index 3a21a4686c..deedc968cf 100644
@@ -3333,7 +3333,7 @@ static void *migration_thread(void *opaque)
 
     qemu_savevm_state_setup(s->to_dst_file);
 
-    if (qemu_savevm_nr_failover_devices()) {
+    if (qemu_savevm_state_guest_unplug_pending()) {
         migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
                           MIGRATION_STATUS_WAIT_UNPLUG);
 
migration/savevm.c +3 -21
index f19cb9ec7a..1d4220ece8 100644
@@ -1140,36 +1140,18 @@ void qemu_savevm_state_header(QEMUFile *f)
     }
 }
 
-int qemu_savevm_nr_failover_devices(void)
+bool qemu_savevm_state_guest_unplug_pending(void)
 {
     SaveStateEntry *se;
-    int n = 0;
 
     QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
         if (se->vmsd && se->vmsd->dev_unplug_pending &&
             se->vmsd->dev_unplug_pending(se->opaque)) {
-            n++;
-        }
-    }
-
-    return n;
-}
-
-bool qemu_savevm_state_guest_unplug_pending(void)
-{
-    SaveStateEntry *se;
-    int n = 0;
-
-    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
-        if (!se->vmsd || !se->vmsd->dev_unplug_pending) {
-            continue;
-        }
-        if (se->vmsd->dev_unplug_pending(se->opaque)) {
-            n++;
+            return true;
         }
     }
 
-    return n > 0;
+    return false;
 }
 
 void qemu_savevm_state_setup(QEMUFile *f)
migration/savevm.h +0 -1
index c42b9c80ee..ba64a7e271 100644
@@ -31,7 +31,6 @@
 
 bool qemu_savevm_state_blocked(Error **errp);
 void qemu_savevm_state_setup(QEMUFile *f);
-int qemu_savevm_nr_failover_devices(void);
 bool qemu_savevm_state_guest_unplug_pending(void);
 int qemu_savevm_state_resume_prepare(MigrationState *s);
 void qemu_savevm_state_header(QEMUFile *f);
Signature · 1 line
2.19.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Keqian Zhu

qemu_savevm_nr_failover_devices() is originally designed to get the number of failover devices, but it actually returns the number of "unplug-pending" failover devices now. Moreover, what drives migration state to wait-unplug should be the number of "unplug-pending" failover devices, not all failover devices.

We can also notice that qemu_savevm_state_guest_unplug_pending() and qemu_savevm_nr_failover_devices() is equivalent almost (from the code view). So the latter is incorrect semantically and useless, just delete it.

Quoted 5 lines

In the qemu_savevm_state_guest_unplug_pending(), once hit a unplug-pending failover device, then it can return true right now to save cpu time.

For my reading you are right:
- 1st function naming is not right
- 2nd function achieves exactly the same effect

I will wait until Jens says anything, but then I will queue it.

Thanks, Juan.

author
#2 lore raw
Quoted 24 lines · Juan Quintela
Quoted 11 lines · Keqian Zhu

qemu_savevm_nr_failover_devices() is originally designed to get the number of failover devices, but it actually returns the number of "unplug-pending" failover devices now. Moreover, what drives migration state to wait-unplug should be the number of "unplug-pending" failover devices, not all failover devices.

We can also notice that qemu_savevm_state_guest_unplug_pending() and qemu_savevm_nr_failover_devices() is equivalent almost (from the code view). So the latter is incorrect semantically and useless, just delete it.

Quoted 5 lines

In the qemu_savevm_state_guest_unplug_pending(), once hit a unplug-pending failover device, then it can return true right now to save cpu time.

For my reading you are right:
- 1st function naming is not right
- 2nd function achieves exactly the same effect

Quoted 7 lines

I will wait until Jens says anything, but then I will queue it.

Thanks, Juan.

.

Thanks,
Keqian.

Tested-by Reviewed-by on v1 1/1
#3 lore raw
In reply to Keqian Zhu
Quoted 97 lines · Keqian Zhu

qemu_savevm_nr_failover_devices() is originally designed to get the number of failover devices, but it actually returns the number of "unplug-pending" failover devices now. Moreover, what drives migration state to wait-unplug should be the number of "unplug-pending" failover devices, not all failover devices.

We can also notice that qemu_savevm_state_guest_unplug_pending() and qemu_savevm_nr_failover_devices() is equivalent almost (from the code view). So the latter is incorrect semantically and useless, just delete it.

In the qemu_savevm_state_guest_unplug_pending(), once hit a unplug-pending failover device, then it can return true right now to save cpu time.

---
Cc: [email protected]
Cc: Juan Quintela <[email protected]>
Cc: "Dr. David Alan Gilbert" <[email protected]>
---

migration/migration.c |  2 +-
migration/savevm.c    | 24 +++---------------------
migration/savevm.h    |  1 -
3 files changed, 4 insertions(+), 23 deletions(-)
migration/migration.c +1 -1
index 3a21a4686c..deedc968cf 100644
@@ -3333,7 +3333,7 @@ static void *migration_thread(void *opaque)
 
    qemu_savevm_state_setup(s->to_dst_file);
 
-    if (qemu_savevm_nr_failover_devices()) {
+    if (qemu_savevm_state_guest_unplug_pending()) {
        migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
                          MIGRATION_STATUS_WAIT_UNPLUG);
 
migration/savevm.c +3 -21
index f19cb9ec7a..1d4220ece8 100644
@@ -1140,36 +1140,18 @@ void qemu_savevm_state_header(QEMUFile *f)
    }
 }
 
-int qemu_savevm_nr_failover_devices(void)
+bool qemu_savevm_state_guest_unplug_pending(void)
 {
    SaveStateEntry *se;
-    int n = 0;
 
    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
        if (se->vmsd && se->vmsd->dev_unplug_pending &&
            se->vmsd->dev_unplug_pending(se->opaque)) {
-            n++;
-        }
-    }
-
-    return n;
-}
-
-bool qemu_savevm_state_guest_unplug_pending(void)
-{
-    SaveStateEntry *se;
-    int n = 0;
-
-    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
-        if (!se->vmsd || !se->vmsd->dev_unplug_pending) {
-            continue;
-        }
-        if (se->vmsd->dev_unplug_pending(se->opaque)) {
-            n++;
+            return true;
        }
    }
 
-    return n > 0;
+    return false;
 }
 
 void qemu_savevm_state_setup(QEMUFile *f)
migration/savevm.h +0 -1
index c42b9c80ee..ba64a7e271 100644
@@ -31,7 +31,6 @@
 
 bool qemu_savevm_state_blocked(Error **errp);
 void qemu_savevm_state_setup(QEMUFile *f);
-int qemu_savevm_nr_failover_devices(void);
 bool qemu_savevm_state_guest_unplug_pending(void);
 int qemu_savevm_state_resume_prepare(MigrationState *s);
 void qemu_savevm_state_header(QEMUFile *f);
Signature · 1 line
2.19.1

Looks good to me. I tested it and it still works, so

regards
Jens

author
#4 lore raw
Quoted 100 lines · Jens Freimann
Quoted 97 lines · Keqian Zhu

qemu_savevm_nr_failover_devices() is originally designed to get the number of failover devices, but it actually returns the number of "unplug-pending" failover devices now. Moreover, what drives migration state to wait-unplug should be the number of "unplug-pending" failover devices, not all failover devices.

We can also notice that qemu_savevm_state_guest_unplug_pending() and qemu_savevm_nr_failover_devices() is equivalent almost (from the code view). So the latter is incorrect semantically and useless, just delete it.

In the qemu_savevm_state_guest_unplug_pending(), once hit a unplug-pending failover device, then it can return true right now to save cpu time.

---
Cc: [email protected]
Cc: Juan Quintela <[email protected]>
Cc: "Dr. David Alan Gilbert" <[email protected]>
---

migration/migration.c |  2 +-
migration/savevm.c    | 24 +++---------------------
migration/savevm.h    |  1 -
3 files changed, 4 insertions(+), 23 deletions(-)
migration/migration.c +1 -1
index 3a21a4686c..deedc968cf 100644
@@ -3333,7 +3333,7 @@ static void *migration_thread(void *opaque)
 
    qemu_savevm_state_setup(s->to_dst_file);
 
-    if (qemu_savevm_nr_failover_devices()) {
+    if (qemu_savevm_state_guest_unplug_pending()) {
        migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
                          MIGRATION_STATUS_WAIT_UNPLUG);
 
migration/savevm.c +3 -21
index f19cb9ec7a..1d4220ece8 100644
@@ -1140,36 +1140,18 @@ void qemu_savevm_state_header(QEMUFile *f)
    }
 }
 
-int qemu_savevm_nr_failover_devices(void)
+bool qemu_savevm_state_guest_unplug_pending(void)
 {
    SaveStateEntry *se;
-    int n = 0;
 
    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
        if (se->vmsd && se->vmsd->dev_unplug_pending &&
            se->vmsd->dev_unplug_pending(se->opaque)) {
-            n++;
-        }
-    }
-
-    return n;
-}
-
-bool qemu_savevm_state_guest_unplug_pending(void)
-{
-    SaveStateEntry *se;
-    int n = 0;
-
-    QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {
-        if (!se->vmsd || !se->vmsd->dev_unplug_pending) {
-            continue;
-        }
-        if (se->vmsd->dev_unplug_pending(se->opaque)) {
-            n++;
+            return true;
        }
    }
 
-    return n > 0;
+    return false;
 }
 
 void qemu_savevm_state_setup(QEMUFile *f)
migration/savevm.h +0 -1
index c42b9c80ee..ba64a7e271 100644
@@ -31,7 +31,6 @@
 
 bool qemu_savevm_state_blocked(Error **errp);
 void qemu_savevm_state_setup(QEMUFile *f);
-int qemu_savevm_nr_failover_devices(void);
 bool qemu_savevm_state_guest_unplug_pending(void);
 int qemu_savevm_state_resume_prepare(MigrationState *s);
 void qemu_savevm_state_header(QEMUFile *f);
Signature · 1 line
2.19.1

Looks good to me. I tested it and it still works, so

Quoted 8 lines

regards
Jens

.

Thanks,
Keqian.