Skip to contentSkip to conversation

Introduce "info migrate-times" monitor command

PATCH Superseded Michal Novotny 2 participants 7 messages Jul 13, 2011 – Jul 14, 2011

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Introduce "info migrate-times" monitor command

Hi,
this is the implementation of the "info migrate-times" command I did to get the times for the migration to get times for each migration stage. Based on the fact migration itself is just the vmsave on the source host and vmload on destination host this function can be also useful to get the save times however it's main purpose is measuring the migration times therefore it's called "info migrate-times". The total memory transferred during the last migration is being tracked there as well as total migration time, time of waiting for input data, times for various migration stages for total value, disk (if applicable) and ram memory transfer. There's also the time difference which is the inaccuracy value which is caused by block device flushing and also the qemu_get_clock_ns() is being used in there and subsequent calls of this function may result into minor inaccuracies (in the matter smaller than of milliseconds).

I also did the testing with various migration speed settings (using the set_migrate_speed monitor command) for 7 GiB RHEL-6 i386 guest running bonnie++ test for 14 GiB (2x RAM) and the results were as follows:

Max.speed | Memory transferred | Time (s)
--------------+-----------------------------+----------------

     32m      |       12 925 676 bytes      |      199 s
     64m      |        7 745 224 bytes      |       26 s
    128m      |        7 674 188 bytes      |       16 s
    256m      |        7 628 988 bytes      |       16 s
    512m      |        7 599 837 bytes      |       15 s
  1024m (1g)  |        7 592 934 bytes      |       14 s
     10g      |        7 583 824 bytes      |       13 s

This has been tested on the 1 GiB network using the remote migration.

The output of the command for last iteration (shown as an example was):

(qemu) info migrate-times
Total transferred memory: 7583824 kbytes
Total migration time: 13.552894 s
Waiting for input data: 6.942414 s
Time difference (inaccuracy): 0.018257 s
Times for total stage 1: 0.020247 s
Times for total stage 2: 6.355092 s
Times for total stage 3: 0.253398 s
Times for total total: 6.628737 s
Times for ram stage 1: 0.020238 s
Times for ram stage 2: 6.353832 s
Times for ram stage 3: 0.228953 s
Times for ram total: 6.603023 s
(qemu)

So please review. This patch could be useful for getting the migration stage times.

Thanks,
Michal

---
 arch_init.c       |   12 +++++-
 block-migration.c |    5 ++
 hmp-commands.hx   |    2 +
 migration.c       |  105 +++++++++++++++++++++++++++++++++++++++++++++
 migration.h       |    4 ++
 monitor.c         |    8 +++
 savevm.c          |   50 ++++++++++++++++++---
 sysemu.h          |    6 +++
 vl.c              |  123 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 307 insertions(+), 8 deletions(-)
arch_init.c +11 -1
index 484b39d..684ae3c 100644
@@ -252,8 +252,12 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
 {
     ram_addr_t addr;
     uint64_t bytes_transferred_last;
+    uint64_t t_start;
     double bwidth = 0;
     uint64_t expected_time = 0;
+    int retval = 0;
+
+    t_start = qemu_get_clock_ns(host_clock);
 
     if (stage < 0) {
         cpu_physical_memory_set_dirty_tracking(0);
@@ -272,6 +276,10 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
         last_offset = 0;
         sort_ram_list();
 
+        time_set("ram", 1, 0);
+        time_set("ram", 2, 0);
+        time_set("ram", 3, 0);
+
         /* Make sure all dirty bits are set */
         QLIST_FOREACH(block, &ram_list.blocks, next) {
             for (addr = block->offset; addr < block->offset + block->length;
@@ -331,8 +339,10 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
     qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
 
     expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
+    retval = (stage == 2) && (expected_time <= migrate_max_downtime());
 
-    return (stage == 2) && (expected_time <= migrate_max_downtime());
+    time_add2("ram", stage, qemu_get_clock_ns(host_clock), t_start);
+    return retval;
 }
 
 static inline void *host_from_stream_offset(QEMUFile *f,
block-migration.c +5 -0
index 0936c7d..b53a1f4 100644
@@ -17,6 +17,8 @@
 #include "qemu-queue.h"
 #include "qemu-timer.h"
 #include "monitor.h"
+#include "qemu-timer.h"
+#include "sysemu.h"
 #include "block-migration.h"
 #include "migration.h"
 #include "blockdev.h"
@@ -556,6 +558,7 @@ static void blk_mig_cleanup(Monitor *mon)
 
 static int block_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
 {
+    uint64_t t_start = qemu_get_clock_ns(host_clock);
     DPRINTF("Enter save live stage %d submitted %d transferred %d\n",
             stage, block_mig_state.submitted, block_mig_state.transferred);
 
@@ -633,6 +636,8 @@ static int block_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
 
     qemu_put_be64(f, BLK_MIG_FLAG_EOS);
 
+    time_add2("disk", stage, qemu_get_clock_ns(host_clock), t_start);
+
     return ((stage == 2) && is_stage2_completed());
 }
 
hmp-commands.hx +2 -0
index 6ad8806..83b33c8 100644
@@ -1345,6 +1345,8 @@ show CPU statistics
 show user network stack connection states
 @item info migrate
 show migration status
+@item info migrate-times
+show migration times for last non-active migration
 @item info balloon
 show balloon information
 @item info qtree
migration.c +105 -0

147 lines not on this page · raw message

migration.h +4 -0
index 050c56c..ef61f3f 100644
@@ -70,6 +70,10 @@ void do_info_migrate_print(Monitor *mon, const QObject *data);
 
 void do_info_migrate(Monitor *mon, QObject **ret_data);
 
+void do_info_migrate_times_print(Monitor *mon, const QObject *data);
+
+void do_info_migrate_times(Monitor *mon, QObject **ret_data);
+
 int exec_start_incoming_migration(const char *host_port);
 
 MigrationState *exec_start_outgoing_migration(Monitor *mon,
monitor.c +8 -0
index 67ceb46..ac555f3 100644
@@ -3060,6 +3060,14 @@ static const mon_cmd_t info_cmds[] = {
         .mhandler.info_new = do_info_migrate,
     },
     {
+        .name       = "migrate-times",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show migration times",
+        .user_print = do_info_migrate_times_print,
+        .mhandler.info_new = do_info_migrate_times,
+    },
+    {
         .name       = "balloon",
         .args_type  = "",
         .params     = "",
savevm.c +43 -7

111 lines not on this page · raw message

sysemu.h +6 -0
index d3013f5..c533706 100644
@@ -77,6 +77,12 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f);
 void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f);
 int qemu_loadvm_state(QEMUFile *f);
 
+uint64_t time_get(const char *name, int stage);
+void time_set(const char *name, int stage, uint64_t tv);
+void time_add(const char *name, int stage, uint64_t tv);
+void time_add2(const char *name, int stage, uint64_t time1, uint64_t time2);
+uint64_t save_total_time(void);
+
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
vl.c +123 -0

135 lines not on this page · raw message

Signature · 1 line
1.7.3.2
#1 lore raw

sysemu.h int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f); · line 84

Quoted 5 lines · Michal Novotny
sysemu.h +5 -0
+uint64_t time_get(const char *name, int stage);
+void time_set(const char *name, int stage, uint64_t tv);
+void time_add(const char *name, int stage, uint64_t tv);
+void time_add2(const char *name, int stage, uint64_t time1, uint64_t time2);
+uint64_t save_total_time(void);

Please inline all these instead of adding new functions.

Quoted 9 lines
sysemu.h +1 -0
+
  /* SLIRP */
  void do_info_slirp(Monitor *mon);
vl.c +0 -0
index fcd7395..340cbe3 100644

vl.c unsigned int nb_prom_envs = 0; · line 236

Quoted 8 lines
vl.c +5 -0
@@ -229,6 +229,12 @@ unsigned int nb_prom_envs = 0;
  const char *prom_envs[MAX_PROM_ENVS];
  int boot_menu;
 
+/* Times */
+static uint64_t time_save_total[3];
+static uint64_t time_save_disk[3];
+static uint64_t time_save_ram[3];
+static uint64_t time_save_wait_input;

Please move these to savevm.c instead. The implementation of the monitor command can also go to savevm.c.

Thanks,

Paolo

#2 lore raw
Quoted 7 lines · Paolo Bonzini

sysemu.h int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f); · line 84

Quoted 5 lines · Michal Novotny
sysemu.h +5 -0
+uint64_t time_get(const char *name, int stage);
+void time_set(const char *name, int stage, uint64_t tv);
+void time_add(const char *name, int stage, uint64_t tv);
+void time_add2(const char *name, int stage, uint64_t time1, uint64_t time2);
+uint64_t save_total_time(void);

Please inline all these instead of adding new functions.

Do you mean to implement as macros? I'm trying since yesterday and it's not that simple because the variable has to be accessible from 3 files - arch_init.c, savevm.c and migration.c. So I need to figure out what file to put the variables to to make it working fine.

Also, I'm thinking about extending it not just to measure save process times but also measure load process times.
Thanks,
Michal

Signature · 2 lines
Michal Novotny <[email protected]>, RHCE, Red Hat
Virtualization | libvirt-php bindings | php-virt-control.org
#3 lore raw
Quoted 6 lines · Michal Novotny
Quoted 1 line

Please inline all these instead of adding new functions.

Do you mean to implement as macros? I'm trying since yesterday and it's not that simple because the variable has to be accessible from 3 files - arch_init.c, savevm.c and migration.c. So I need to figure out what file to put the variables to to make it working fine.

I would like to avoid using them in multiple files.

The simplest change is to remove migration.c from the list. The "waiting for input" handling can be moved to qemu_savevm_state_begin and qemu_savevm_state_iterate. The monitor code can be moved to savevm.c as well.

And also, it makes no sense that arch_init.c includes savevm-related code. It was done simply to avoid compiling savevm more than once (to put it in Makefile.objs instead of Makefile.target). If you move that code back to savevm.c, the list of files goes down to one.

Paolo

#4 lore raw
Quoted 13 lines · Paolo Bonzini
Quoted 5 lines · Michal Novotny
Quoted 1 line

Please inline all these instead of adding new functions.

Do you mean to implement as macros? I'm trying since yesterday and it's not that simple because the variable has to be accessible from 3 files - arch_init.c, savevm.c and migration.c. So I need to figure out what file to put the variables to to make it working fine.

I would like to avoid using them in multiple files.

The simplest change is to remove migration.c from the list. The "waiting for input" handling can be moved to qemu_savevm_state_begin and qemu_savevm_state_iterate. The monitor code can be moved to savevm.c as well.

Quoted 6 lines

And also, it makes no sense that arch_init.c includes savevm-related code. It was done simply to avoid compiling savevm more than once (to put it in Makefile.objs instead of Makefile.target). If you move that code back to savevm.c, the list of files goes down to one.

Paolo

I already sent the version 2 of my patch including both time measuring support for each of the 4 parts of loadvm and also for savevm. The monitor command implementation has been moved to the savevm.c and I have to react to some points from your e-mail although I read it now (after it's been already sent to the qemu-devel list).

What do you mean by removing migration.c from the list? Do you mean doing no modifications to this file? The wait for input stage makes time differences if it's moved into the qemu_savevm_state_{begin|iterate} - although it's about milliseconds. If we consider this is acceptable we need to take in mind that this function may be called many times which would result into some bigger differences when we sum the time values together.

The arch_init.c to include savevm-related code doesn't make any sense in general which is the thing I have to agree but if we want to measure the ram_save_live() per each stage we need to alter the ram_save_live() function which is present in the arch_init.c file (this is directly in vl.c file for RHEL-6 version of qemu however for upstream version we need to modify arch_init.c to provide the most precise RAM transfer values per each stage). We can move the ram_save_live() function into some other file, like savevm.c or vl.c... Is this what you mean by "If you move that code back to savevm.c" ? The code is in vl.c file for RHEL-6, not savevm.c and I don't know whether it ever was in savevm.c .

Thanks,
Michal

Signature · 2 lines
Michal Novotny <[email protected]>, RHCE, Red Hat
Virtualization | libvirt-php bindings | php-virt-control.org
#5 lore raw
Quoted 2 lines · Michal Novotny

What do you mean by removing migration.c from the list? Do you mean doing no modifications to this file?

No usage of the time variables in migration.c.

Quoted 1 line

it's about milliseconds

It's noise anyway.

Quoted 10 lines

The arch_init.c to include savevm-related code doesn't make any sense in general which is the thing I have to agree but if we want to measure the ram_save_live() per each stage we need to alter the ram_save_live() function which is present in the arch_init.c file (this is directly in vl.c file for RHEL-6 version of qemu however for upstream version we need to modify arch_init.c to provide the most precise RAM transfer values per each stage). We can move the ram_save_live() function into some other file, like savevm.c or vl.c... Is this what you mean by "If you move that code back to savevm.c" ? The code is in vl.c file for RHEL-6, not savevm.c and I don't know whether it ever was in savevm.c .

I think savevm.c is the right place for it.

Alternatively, what about updating the information for ram and disk directly in qemu_savevm_state_begin/iterate/complete (and similarly for loading)? Just change "disk" to "block" so that it matches the parameter of register_savevm_live in block-migration.c.

Paolo

#6 lore raw
Quoted 18 lines · Paolo Bonzini
Quoted 2 lines · Michal Novotny

What do you mean by removing migration.c from the list? Do you mean doing no modifications to this file?

No usage of the time variables in migration.c.

Quoted 1 line

it's about milliseconds

It's noise anyway.

Quoted 10 lines

The arch_init.c to include savevm-related code doesn't make any sense in general which is the thing I have to agree but if we want to measure the ram_save_live() per each stage we need to alter the ram_save_live() function which is present in the arch_init.c file (this is directly in vl.c file for RHEL-6 version of qemu however for upstream version we need to modify arch_init.c to provide the most precise RAM transfer values per each stage). We can move the ram_save_live() function into some other file, like savevm.c or vl.c... Is this what you mean by "If you move that code back to savevm.c" ? The code is in vl.c file for RHEL-6, not savevm.c and I don't know whether it ever was in savevm.c .

Quoted 8 lines

I think savevm.c is the right place for it.

Alternatively, what about updating the information for ram and disk directly in qemu_savevm_state_begin/iterate/complete (and similarly for loading)? Just change "disk" to "block" so that it matches the parameter of register_savevm_live in block-migration.c.

Paolo

Ok, I can see what you mean now however the v2 has been already sent so I'll wait for feedback on this version since there may be some new points that comes to your (or any other's) mind when reviewing v2 :-)

Thanks,
Michal

Signature · 2 lines
Michal Novotny <[email protected]>, RHCE, Red Hat
Virtualization | libvirt-php bindings | php-virt-control.org