rdma: core logic
v3 cover rdma: core logic
From: "Michael R. Hines" <[email protected]>
Changes since v2:
- trivial bugfix
- re-ran checkpatch
Michael R. Hines (8):
rdma: update documentation to reflect new unpin support
rdma: bugfix: ram_control_save_page()
rdma: introduce ram_handle_compressed()
rdma: core logic
rdma: send pc.ram
rdma: allow state transitions between other states besides ACTIVE
rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state
transition
rdma: account for the time spent in MIG_STATE_SETUP through QMP
Makefile.objs | 1 + arch_init.c | 62 +- configure | 40 + docs/rdma.txt | 51 +- hmp.c | 4 + include/migration/migration.h | 7 + migration-rdma.c | 3249 +++++++++++++++++++++++++++++++++++++++++ migration.c | 48 +- qapi-schema.json | 9 +- savevm.c | 2 +- 10 files changed, 3427 insertions(+), 46 deletions(-) create mode 100644 migration-rdma.c
Signature · 1 line
1.7.10.4
PATCH RESEND v3 1/8 rdma: update documentation to reflect new unpin support
From: "Michael R. Hines" <[email protected]>
As requested, the protocol now includes memory unpinning support. This has been implemented in a non-optimized manner, in such a way that one could devise an LRU or other workload-specific information on top of the basic mechanism to influence the way unpinning happens during runtime.
The feature is not yet user-facing, and is thus can only be enabled at compile-time.
--- docs/rdma.txt | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-)
docs/rdma.txt +30 -21
@@ -35,7 +35,7 @@ memory tracked during each live migration iteration round cannot keep pace with the rate of dirty memory produced by the workload. RDMA currently comes in two flavors: both Ethernet based (RoCE, or RDMA -over Convered Ethernet) as well as Infiniband-based. This implementation of +over Converged Ethernet) as well as Infiniband-based. This implementation of migration using RDMA is capable of using both technologies because of the use of the OpenFabrics OFED software stack that abstracts out the programming model irrespective of the underlying hardware.
@@ -188,9 +188,9 @@ header portion and a data portion (but together are transmitted as a single SEND message). Header: - * Length (of the data portion, uint32, network byte order) - * Type (what command to perform, uint32, network byte order) - * Repeat (Number of commands in data portion, same type only) + * Length (of the data portion, uint32, network byte order) + * Type (what command to perform, uint32, network byte order) + * Repeat (Number of commands in data portion, same type only) The 'Repeat' field is here to support future multiple page registrations in a single message without any need to change the protocol itself
@@ -202,17 +202,19 @@ The maximum number of repeats is hard-coded to 4096. This is a conservative limit based on the maximum size of a SEND message along with emperical observations on the maximum future benefit of simultaneous page registrations. -The 'type' field has 10 different command values: - 1. Unused - 2. Error (sent to the source during bad things) - 3. Ready (control-channel is available) - 4. QEMU File (for sending non-live device state) - 5. RAM Blocks request (used right after connection setup) - 6. RAM Blocks result (used right after connection setup) - 7. Compress page (zap zero page and skip registration) - 8. Register request (dynamic chunk registration) - 9. Register result ('rkey' to be used by sender) - 10. Register finished (registration for current iteration finished) +The 'type' field has 12 different command values: + 1. Unused + 2. Error (sent to the source during bad things) + 3. Ready (control-channel is available) + 4. QEMU File (for sending non-live device state) + 5. RAM Blocks request (used right after connection setup) + 6. RAM Blocks result (used right after connection setup) + 7. Compress page (zap zero page and skip registration) + 8. Register request (dynamic chunk registration) + 9. Register result ('rkey' to be used by sender) + 10. Register finished (registration for current iteration finished) + 11. Unregister request (unpin previously registered memory) + 12. Unregister finished (confirmation that unpin completed) A single control message, as hinted above, can contain within the data portion an array of many commands of the same type. If there is more than
@@ -243,7 +245,7 @@ qemu_rdma_exchange_send(header, data, optional response header & data): from the receiver to tell us that the receiver is *ready* for us to transmit some new bytes. 2. Optionally: if we are expecting a response from the command - (that we have no yet transmitted), let's post an RQ + (that we have not yet transmitted), let's post an RQ work request to receive that data a few moments later. 3. When the READY arrives, librdmacm will unblock us and we immediately post a RQ work request
@@ -293,8 +295,10 @@ librdmacm provides the user with a 'private data' area to be exchanged at connection-setup time before any infiniband traffic is generated. Header: - * Version (protocol version validated before send/recv occurs), uint32, network byte order - * Flags (bitwise OR of each capability), uint32, network byte order + * Version (protocol version validated before send/recv occurs), + uint32, network byte order + * Flags (bitwise OR of each capability), + uint32, network byte order There is no data portion of this header right now, so there is no length field. The maximum size of the 'private data' section
@@ -313,7 +317,7 @@ If the version is invalid, we throw an error. If the version is new, we only negotiate the capabilities that the requested version is able to perform and ignore the rest. -Currently there is only *one* capability in Version #1: dynamic page registration +Currently there is only one capability in Version #1: dynamic page registration Finally: Negotiation happens with the Flags field: If the primary-VM sets a flag, but the destination does not support this capability, it
@@ -326,8 +330,8 @@ QEMUFileRDMA Interface: QEMUFileRDMA introduces a couple of new functions: -1. qemu_rdma_get_buffer() (QEMUFileOps rdma_read_ops) -2. qemu_rdma_put_buffer() (QEMUFileOps rdma_write_ops) +1. qemu_rdma_get_buffer() (QEMUFileOps rdma_read_ops) +2. qemu_rdma_put_buffer() (QEMUFileOps rdma_write_ops) These two functions are very short and simply use the protocol describe above to deliver bytes without changing the upper-level
@@ -413,3 +417,8 @@ TODO: the use of KSM and ballooning while using RDMA. 4. Also, some form of balloon-device usage tracking would also help alleviate some issues. +5. Move UNREGISTER requests to a separate thread. +6. Use LRU to provide more fine-grained direction of UNREGISTER + requests for unpinning memory in an overcommitted environment. +7. Expose UNREGISTER support to the user by way of workload-specific + hints about application behavior.
Signature · 1 line
1.7.10.4
PATCH RESEND v3 2/8 rdma: bugfix: ram_control_save_page()
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
We were not checking for a valid 'bytes_sent' pointer before accessing it.
--- savevm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
savevm.c +1 -1
@@ -662,7 +662,7 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset, offset, size, bytes_sent);if (ret !=RAM_SAVE_CONTROL_DELAYED ) { -if (*bytes_sent >0 ) { +if (bytes_sent && *bytes_sent >0 ) {qemu_update_position (f, *bytes_sent); }else if (ret <0 ) {qemu_file_set_error (f, ret);
Signature · 1 line
1.7.10.4
PATCH RESEND v3 3/8 rdma: introduce ram_handle_compressed()
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
This gives RDMA shared access to madvise() on the destination side when an entire chunk is found to be zero.
--- arch_init.c | 29 +++++++++++++++++++---------- include/migration/migration.h | 2 ++ 2 files changed, 21 insertions(+), 10 deletions(-)
arch_init.c +19 -10
@@ -777,6 +777,24 @@ static inline void *host_from_stream_offset(QEMUFile *f,return NULL ; } +/* +* If a page (or a whole RDMA chunk) has been +* determined to be zero, then zap it. +*/ +void ram_handle_compressed (void *host,uint8_t ch,uint64_t size) +{ +if (ch !=0 || !is_zero_page (host)) { +memset (host, ch, size); +#ifndef _WIN32 +if (ch ==0 && + (!kvm_enabled () ||kvm_has_sync_mmu ()) && +getpagesize () <=TARGET_PAGE_SIZE ) { +qemu_madvise (host,TARGET_PAGE_SIZE ,QEMU_MADV_DONTNEED ); + } +#endif + } +} +static int ram_load (QEMUFile *f,void *opaque,int version_id) {ram_addr_t addr;
@@ -848,16 +866,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) } ch =qemu_get_byte (f); -if (ch !=0 || !is_zero_page (host)) { -memset (host, ch,TARGET_PAGE_SIZE ); -#ifndef _WIN32 -if (ch ==0 && - (!kvm_enabled () ||kvm_has_sync_mmu ()) && -getpagesize () <=TARGET_PAGE_SIZE ) { -qemu_madvise (host,TARGET_PAGE_SIZE ,QEMU_MADV_DONTNEED ); - } -#endif - } +ram_handle_compressed (host, ch,TARGET_PAGE_SIZE ); }else if (flags &RAM_SAVE_FLAG_PAGE ) {void *host;
include/migration/migration.h +2 -0
@@ -109,6 +109,8 @@ uint64_t xbzrle_mig_pages_transferred(void);uint64_t xbzrle_mig_pages_overflow (void );uint64_t xbzrle_mig_pages_cache_miss (void ); +void ram_handle_compressed (void *host,uint8_t ch,uint64_t size); +/** * @migrate_add_blocker - prevent migration from proceeding *
Signature · 1 line
1.7.10.4
PATCH RESEND v3 4/8 rdma: core logic
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
Code that does need to be visible is kept well contained inside this file and this is the only new additional file to the entire patch.
This file includes the entire protocol and interfaces required to perform RDMA migration.
Also, the configure and Makefile modifications to link this file are included.
Full documentation is in docs/rdma.txt
--- Makefile.objs | 1 + configure | 40 + include/migration/migration.h | 4 + migration-rdma.c | 3249 +++++++++++++++++++++++++++++++++++++++++ migration.c | 8 + 5 files changed, 3302 insertions(+) create mode 100644 migration-rdma.c
Makefile.objs +1 -0
@@ -51,6 +51,7 @@ common-obj-$(CONFIG_POSIX) += os-posix.o common-obj-$(CONFIG_LINUX) += fsdev/ common-obj-y += migration.o migration-tcp.o +common-obj-$(CONFIG_RDMA) += migration-rdma.o common-obj-y += qemu-char.o #aio.o common-obj-y += block-migration.o common-obj-y += page_cache.o xbzrle.o
configure +40 -0
@@ -180,6 +180,7 @@ xfs="" vhost_net="no" vhost_scsi="no" kvm="no" +rdma="" gprof="no" debug_tcg="no" debug="no"
@@ -936,6 +937,10 @@ for opt do ;; --enable-gtk) gtk="yes" ;; + --enable-rdma) rdma="yes" + ;; + --disable-rdma) rdma="no" + ;; --with-gtkabi=*) gtkabi="$optarg" ;; --enable-tpm) tpm="yes"
@@ -1094,6 +1099,8 @@ echo " --enable-bluez enable bluez stack connectivity" echo " --disable-slirp disable SLIRP userspace network connectivity" echo " --disable-kvm disable KVM acceleration support" echo " --enable-kvm enable KVM acceleration support" +echo " --disable-rdma disable RDMA-based migration support" +echo " --enable-rdma enable RDMA-based migration support" echo " --enable-tcg-interpreter enable TCG with bytecode interpreter (TCI)" echo " --disable-nptl disable usermode NPTL support" echo " --enable-nptl enable usermode NPTL support"
@@ -1797,6 +1804,30 @@ EOF fi ########################################## +# RDMA needs OpenFabrics libraries +if test "$rdma" != "no" ; then + cat > $TMPC <<EOF +#include <rdma/rdma_cma.h> +int main(void) { return 0; } +EOF + rdma_libs="-lrdmacm -libverbs" + if compile_prog "" "$rdma_libs" ; then + rdma="yes" + libs_softmmu="$libs_softmmu $rdma_libs" + else + if test "$rdma" = "yes" ; then + error_exit \ + " OpenFabrics librdmacm/libibverbs not present." \ + " Your options:" \ + " (1) Fast: Install infiniband packages from your distro." \ + " (2) Cleanest: Install libraries from www.openfabrics.org" \ + " (3) Also: Install softiwarp if you don't have RDMA hardware" + fi + rdma="no" + fi +fi + +########################################## # VNC TLS/WS detection if test "$vnc" = "yes" -a \( "$vnc_tls" != "no" -o "$vnc_ws" != "no" \) ; then cat > $TMPC <<EOF
@@ -3555,6 +3586,7 @@ echo "Linux AIO support $linux_aio" echo "ATTR/XATTR support $attr" echo "Install blobs $blobs" echo "KVM support $kvm" +echo "RDMA support $rdma" echo "TCG interpreter $tcg_interpreter" echo "fdt support $fdt" echo "preadv support $preadv"
@@ -4039,6 +4071,10 @@ if test "$trace_default" = "yes"; then echo "CONFIG_TRACE_DEFAULT=y" >> $config_host_mak fi +if test "$rdma" = "yes" ; then + echo "CONFIG_RDMA=y" >> $config_host_mak +fi + if test "$tcg_interpreter" = "yes"; then QEMU_INCLUDES="-I\$(SRC_PATH)/tcg/tci $QEMU_INCLUDES" elif test "$ARCH" = "sparc64" ; then
@@ -4478,6 +4514,10 @@ if [ "$pixman" = "internal" ]; then echo "config-host.h: subdir-pixman" >> $config_host_mak fi +if test "$rdma" = "yes" ; then +echo "CONFIG_RDMA=y" >> $config_host_mak +fi + if [ "$dtc_internal" = "yes" ]; then echo "config-host.h: subdir-dtc" >> $config_host_mak fi
include/migration/migration.h +4 -0
@@ -77,6 +77,10 @@ void fd_start_incoming_migration(const char *path, Error **errp);void fd_start_outgoing_migration (MigrationState *s,const char *fdname,Error **errp); +void rdma_start_outgoing_migration (void *opaque,const char *host_port,Error **errp); + +void rdma_start_incoming_migration (const char *host_port,Error **errp); +void migrate_fd_error (MigrationState *s);void migrate_fd_connect (MigrationState *s);
migration-rdma.c new file +3249 -0
2,901 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.10.4
Part of the diff is not shown here. View the raw message.
Quoted 6 lines · On Tue, 2013-07-16 at 12:48 -0400, [email protected] wrote:
From: "Michael R. Hines" <[email protected]>
Code that does need to be visible is kept well contained inside this file and this is the only new additional file to the entire patch.
Quoted 8 lines
This file includes the entire protocol and interfaces required to perform RDMA migration.
Also, the configure and
Makefilemodifications to link this file are included.Full documentation is in
docs/rdma.txt
This patch is too big (in my opinion).
I would split it into at least 3 patches:
1. Generic RDMA code (this part can be reused by everyone who will need RDMA in the future)
2. RDMA transfer protocol (separating this will give us possibility for optimization without touching the rest of the code)
3. Migration related code
migration-rdma.c line 129
Quoted 4 lines
+ */
migration-rdma.c new file +3
-0+#define RDMA_WRID_TYPE_SHIFT 0UL +#define RDMA_WRID_BLOCK_SHIFT 16UL +#define RDMA_WRID_CHUNK_SHIFT 30UL
If I understand correctly each RDMA write is exactly 1MB.
I think that it is crucial from the performance point of view to make this configurable. Sometimes the time to register the MR(and unregister) on both machines may be the same as transmission of 1MB. Bottom line, this cannot be hard-coded because it depends on the connection speed.
Quoted 25 lines
migration-rdma.c new file +25
-0+/* +* RDMA requires memory registration (mlock/pinning), but this is not good for +* overcommitment. +* +* In preparation for the future where LRU information or workload-specific +* writable writable working set memory access behavior is available to QEMU +* it would be nice to have in place the ability to UN-register/UN-pin +* particular memory regions from the RDMA hardware when it is determine that +* those regions of memory will likely not be accessed again in the near future. +* +* While we do not yet have such information right now, the following +* compile-time option allows us to perform a non-optimized version of this +* behavior. +* +* By uncommenting this option, you will cause *all* RDMA transfers to be +* unregistered immediately after the transfer completes on both sides of the +* connection. This has no effect in 'rdma-pin-all' mode, only regular mode. +* +* This will have a terrible impact on migration performance, so until future +* workload information or LRU information is available, do not attempt to use +* this feature except for basic testing. +*/ +//#define RDMA_UNREGISTRATION_EXAMPLE + +/*
migration-rdma.c line 1099
Quoted 10 lines
migration-rdma.c new file +10
-0+* Perform a non-optimized memory unregistration after every transfer +* for demonsration purposes, only if pin-all is not requested. +* +* Potential optimizations: +* 1. Start a new thread to run this function continuously +- for bit clearing +- and for receipt of unregister messages +* 2. Use an LRU. +* 3. Use workload hints. +*/
I think that if we work with chunks large enough, in such way that the time to pass the pages between hosts is much bigger the MR registration/unregistration, it may solve the issue as least partially (it will not be such an impact).
After that, optimization is a good idea.
Nice work!
Marcel
Quoted 13 lines · Marcel Apfelbaum
Quoted 12 lines · On Tue, 2013-07-16 at 12:48 -0400, [email protected] wrote:
From: "Michael R. Hines" <[email protected]>
Code that does need to be visible is kept well contained inside this file and this is the only new additional file to the entire patch.
This file includes the entire protocol and interfaces required to perform RDMA migration.
Also, the configure and
Makefilemodifications to link this file are included.
Quoted 8 lines
Quoted 2 lines
Full documentation is in
docs/rdma.txtThis patch is too big (in my opinion).
I would split it into at least 3 patches:
1. Generic RDMA code (this part can be reused by everyone who will need RDMA in the future)
2. RDMA transfer protocol (separating this will give us possibility for optimization without touching the rest of the code)
3. Migration related code
Don't let the "v3" mislead you =). The patch actually *used* to look just like what you described (3 different ones), but after more than a dozen reviews since January I was told to join all the code into a single file by the reviewers.
Quoted 9 lines
migration-rdma.c line 129
Quoted 5 lines
+ */
migration-rdma.c new file +3
-0+#define RDMA_WRID_TYPE_SHIFT 0UL +#define RDMA_WRID_BLOCK_SHIFT 16UL +#define RDMA_WRID_CHUNK_SHIFT 30ULIf I understand correctly each RDMA write is exactly 1MB.
I think that it is crucial from the performance point of view to make this configurable. Sometimes the time to register the MR(and unregister) on both machines may be the same as transmission of 1MB. Bottom line, this cannot be hard-coded because it depends on the connection speed.
Yes, that's correct, but you probably missed reading the whole file (it's big, I know). Search for "mergable" in the patch, and you'll see the function.
Chunks are only 1MB *contiguous*. That means that if ram_save_block() does not gives us contiguous pages up to 1MB, then we do not send 1MB - we only send what we were given. For example: if we were given 0.5 of contiguous transfers to perform and then the next page address is far far away, then we transmit that "chunk" immediately without worrying about waiting for anything else.
Quoted 43 lines
Quoted 27 lines
migration-rdma.c new file +25
-0+/* +* RDMA requires memory registration (mlock/pinning), but this is not good for +* overcommitment. +* +* In preparation for the future where LRU information or workload-specific +* writable writable working set memory access behavior is available to QEMU +* it would be nice to have in place the ability to UN-register/UN-pin +* particular memory regions from the RDMA hardware when it is determine that +* those regions of memory will likely not be accessed again in the near future. +* +* While we do not yet have such information right now, the following +* compile-time option allows us to perform a non-optimized version of this +* behavior. +* +* By uncommenting this option, you will cause *all* RDMA transfers to be +* unregistered immediately after the transfer completes on both sides of the +* connection. This has no effect in 'rdma-pin-all' mode, only regular mode. +* +* This will have a terrible impact on migration performance, so until future +* workload information or LRU information is available, do not attempt to use +* this feature except for basic testing. +*/ +//#define RDMA_UNREGISTRATION_EXAMPLE + +/* migration-rdma.c line 1099
Quoted 10 lines
migration-rdma.c new file +10
-0+* Perform a non-optimized memory unregistration after every transfer +* for demonsration purposes, only if pin-all is not requested. +* +* Potential optimizations: +* 1. Start a new thread to run this function continuously +- for bit clearing +- and for receipt of unregister messages +* 2. Use an LRU. +* 3. Use workload hints. +*/ I think that if we work with chunks large enough, in such way that the time to pass the pages between hosts is much bigger the MR registration/unregistration, it may solve the issue as least partially (it will not be such an impact).
After that, optimization is a good idea.
Quoted 3 lines
Nice work!
Marcel
Agreed. Thank you.
- Michael
Il 18/07/2013 14:07, Michael R. Hines ha scritto:
Quoted 25 lines · Marcel Apfelbaum
Quoted 15 lines · On Tue, 2013-07-16 at 12:48 -0400, [email protected] wrote:
Quoted 6 lines
From: "Michael R. Hines" <[email protected]>
Code that does need to be visible is kept well contained inside this file and this is the only new additional file to the entire patch.
Quoted 8 lines
This file includes the entire protocol and interfaces required to perform RDMA migration.
Also, the configure and
Makefilemodifications to link this file are included.Full documentation is in
docs/rdma.txtQuoted 8 lines
This patch is too big (in my opinion).
I would split it into at least 3 patches:
1. Generic RDMA code (this part can be reused by everyone who will need RDMA in the future)
2. RDMA transfer protocol (separating this will give us possibility for optimization without touching the rest of the code)
3. Migration related code
Quoted 5 lines
Don't let the "v3" mislead you =). The patch actually *used* to look just like what
you described (3 different ones), but after more than a dozen reviews since January
I was told to join all the code into a single file by the reviewers.
Yeah, I guess I owe some explanation to Marcel (who is not RDMA-impaired at all). Because the reviewers (me especially) did not know much about RDMA, we initially concentrated on having the right interfaces between migration-rdma.c and the migration core.
Once we had something that core developers considered to be the "right" interfaces, Michael's original split in 1/2/3 didn't make much sense anymore, so in the end it was easier to just merge everything in a single patch and treat it almost as a black box.
Having generic RDMA code in a separate file would be a nice thing, but I don't think it's absolutely necessary in order to merge this code (which I would like to have in 1.6). We have already done "chainsaw" passes on files in the past, at this point I prefer "release early, release often".
Paolo
PATCH RESEND v3 5/8 rdma: send pc.ram
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
This takes advantages of the previous patches:
1. use the new QEMUFileOps hook 'save_page'
2. call out to the right accessor methods to invoke the iteration hooks defined in QEMUFileOps
--- arch_init.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-)
arch_init.c +32 -1
@@ -115,6 +115,7 @@ const uint32_t arch_type = QEMU_ARCH;#define RAM_SAVE_FLAG_EOS 0x10#define RAM_SAVE_FLAG_CONTINUE 0x20#define RAM_SAVE_FLAG_XBZRLE 0x40 +/* 0x80 is reserved in migration.h start with 0x100 next */ static struct defconfig_file {
@@ -447,6 +448,7 @@ static int ram_save_block(QEMUFile *f, bool last_stage) ram_bulk_stage = false; } }else { +int ret;uint8_t *p;int cont = (block == last_sent_block) ?RAM_SAVE_FLAG_CONTINUE :0 ;
@@ -455,7 +457,18 @@ static int ram_save_block(QEMUFile *f, bool last_stage)/* In doubt sent page as normal */ bytes_sent =-1 ; -if (is_zero_page (p)) { + ret =ram_control_save_page (f, block->offset, + offset,TARGET_PAGE_SIZE , &bytes_sent); + +if (ret !=RAM_SAVE_CONTROL_NOT_SUPP ) { +if (ret !=RAM_SAVE_CONTROL_DELAYED ) { +if (bytes_sent >0 ) { + acct_info.norm_pages++; + }else if (bytes_sent ==0 ) { + acct_info.dup_pages++; + } + } + }else if (is_zero_page (p)) { acct_info.dup_pages++; bytes_sent =save_block_hdr (f, block, offset, cont,RAM_SAVE_FLAG_COMPRESS );
@@ -605,6 +618,10 @@ static int ram_save_setup(QEMUFile *f, void *opaque) }qemu_mutex_unlock_ramlist (); + +ram_control_before_iterate (f,RAM_CONTROL_SETUP ); +ram_control_after_iterate (f,RAM_CONTROL_SETUP ); +qemu_put_be64 (f,RAM_SAVE_FLAG_EOS );return 0 ;
@@ -623,6 +640,8 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)reset_ram_globals (); } +ram_control_before_iterate (f,RAM_CONTROL_ROUND ); + t0 =qemu_get_clock_ns (rt_clock); i =0 ;while ((ret =qemu_file_rate_limit (f)) ==0 ) {
@@ -653,6 +672,12 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)qemu_mutex_unlock_ramlist (); +/* +* Must occur before EOS (or any QEMUFile operation) +* because of RDMA protocol. +*/ +ram_control_after_iterate (f,RAM_CONTROL_ROUND ); +if (ret <0 ) { bytes_transferred += total_sent;return ret;
@@ -670,6 +695,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque)qemu_mutex_lock_ramlist ();migration_bitmap_sync (); +ram_control_before_iterate (f,RAM_CONTROL_FINISH ); +/* try transferring iterative blocks of memory */ /* flush all remaining blocks regardless of rate limiting */
@@ -683,6 +710,8 @@ static int ram_save_complete(QEMUFile *f, void *opaque) } bytes_transferred += bytes_sent; } + +ram_control_after_iterate (f,RAM_CONTROL_FINISH );migration_end ();qemu_mutex_unlock_ramlist ();
@@ -886,6 +915,8 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) ret = -EINVAL ; goto done; } + }else if (flags &RAM_SAVE_FLAG_HOOK ) { +ram_control_load_hook (f, flags); } error =qemu_file_get_error (f);if (error) {
Signature · 1 line
1.7.10.4
PATCH RESEND v3 6/8 rdma: allow state transitions between other states besides ACTIVE
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
This patch is in preparation for the next ones: Until now the MIG_STATE_SETUP state was not really a 'formal' state. It has been used as a 'zero' state and QEMU has been unconditionally transitioning into this state when the QMP migrate command was called. In preparation for timing this state, we have to make this state a a 'real' state which actually gets transitioned from later in the migration_thread() from SETUP => ACTIVE, rather than just automatically dropping into this state at the beginninig of the migration.
This means that the state transition function (migration_finish_set_state()) needs to be capable of transitioning from valid states _other_ than just MIG_STATE_ACTIVE.
The function is in fact already capable of doing that, but was not allowing the old state to be a parameter specified as an input.
This patch fixes that and only makes the transition if the current state matches the old state that the caller intended to transition from.
--- migration.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
migration.c +5 -5
@@ -295,9 +295,9 @@ static void migrate_fd_cleanup(void *opaque)notifier_list_notify (&migration_state_notifiers, s); } -static void migrate_finish_set_state (MigrationState *s,int new_state) +static void migrate_set_state (MigrationState *s,int old_state,int new_state) { -if (atomic_cmpxchg (&s->state,MIG_STATE_ACTIVE , new_state) == new_state) { +if (atomic_cmpxchg (&s->state, old_state, new_state) == new_state) {trace_migrate_set_state (new_state); } }
@@ -315,7 +315,7 @@ static void migrate_fd_cancel(MigrationState *s) {DPRINTF ("cancelling migration\n" ); -migrate_finish_set_state (s,MIG_STATE_CANCELLED ); +migrate_set_state (s, s->state,MIG_STATE_CANCELLED ); }void add_migration_state_change_notifier (Notifier *notify)
@@ -545,14 +545,14 @@ static void *migration_thread(void *opaque)qemu_savevm_state_complete (s->file);qemu_mutex_unlock_iothread ();if (!qemu_file_get_error (s->file)) { -migrate_finish_set_state (s,MIG_STATE_COMPLETED ); +migrate_set_state (s,MIG_STATE_ACTIVE ,MIG_STATE_COMPLETED );break ; } } }if (qemu_file_get_error (s->file)) { -migrate_finish_set_state (s,MIG_STATE_ERROR ); +migrate_set_state (s,MIG_STATE_ACTIVE ,MIG_STATE_ERROR );break ; } current_time =qemu_get_clock_ms (rt_clock);
Signature · 1 line
1.7.10.4
PATCH RESEND v3 7/8 rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
As described in the previous patch, until now, the MIG_STATE_SETUP state was not really a 'formal' state. It has been used as a 'zero' state (what we're calling 'NONE' here) and QEMU has been unconditionally transitioning into this state when the QMP migration command was called. Instead we want to introduce MIG_STATE_NONE, which is our starting state in the state machine, and then immediately transition into the MIG_STATE_SETUP state when the QMP migrate command is issued.
In order to do this, we must delay the transition into MIG_STATE_ACTIVE until later in the migration_thread(). This is done to be able to timestamp the amount of time spent in the SETUP state for proper accounting to the user during an RDMA migration.
Furthermore, the management software, until now, has never been aware of the existence of the SETUP state whatsoever. This must change, because, timing of this state implies that the state actually exists.
These two patches cannot be separated because the 'query_migrate' QMP switch statement needs to know how to handle this new state transition.
--- migration.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
migration.c +14 -7
@@ -36,7 +36,8 @@#endif enum { -MIG_STATE_ERROR , +MIG_STATE_ERROR =-1 , +MIG_STATE_NONE ,MIG_STATE_SETUP ,MIG_STATE_CANCELLED ,MIG_STATE_ACTIVE ,
@@ -63,7 +64,7 @@ static NotifierList migration_state_notifiers =MigrationState *migrate_get_current (void ) {static MigrationState current_migration = { - .state =MIG_STATE_SETUP , + .state =MIG_STATE_NONE , .bandwidth_limit =MAX_THROTTLE , .xbzrle_cache_size =DEFAULT_MIGRATE_CACHE_SIZE , .mbps =-1 ,
@@ -184,9 +185,13 @@ MigrationInfo *qmp_query_migrate(Error **errp)MigrationState *s =migrate_get_current ();switch (s->state) { -case MIG_STATE_SETUP : +case MIG_STATE_NONE :/* no migration has happened ever */ break ; +case MIG_STATE_SETUP : + info->has_status = true; + info->status =g_strdup ("setup" ); +break ;case MIG_STATE_ACTIVE : info->has_status = true; info->status =g_strdup ("active" );
@@ -257,7 +262,7 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,MigrationState *s =migrate_get_current ();MigrationCapabilityStatusList *cap; -if (s->state ==MIG_STATE_ACTIVE ) { +if (s->state ==MIG_STATE_ACTIVE || s->state ==MIG_STATE_SETUP ) {error_set (errp,QERR_MIGRATION_ACTIVE );return ; }
@@ -392,7 +397,7 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk, params.blk = blk; params.shared = inc; -if (s->state ==MIG_STATE_ACTIVE ) { +if (s->state ==MIG_STATE_ACTIVE || s->state ==MIG_STATE_SETUP ) {error_set (errp,QERR_MIGRATION_ACTIVE );return ; }
@@ -524,6 +529,8 @@ static void *migration_thread(void *opaque)DPRINTF ("beginning savevm\n" );qemu_savevm_state_begin (s->file, &s->params); +migrate_set_state (s,MIG_STATE_SETUP ,MIG_STATE_ACTIVE ); +while (s->state ==MIG_STATE_ACTIVE ) {int64_t current_time;uint64_t pending_size;
@@ -603,8 +610,8 @@ static void *migration_thread(void *opaque)void migrate_fd_connect (MigrationState *s) { - s->state =MIG_STATE_ACTIVE ; -trace_migrate_set_state (MIG_STATE_ACTIVE ); + s->state =MIG_STATE_SETUP ; +trace_migrate_set_state (MIG_STATE_SETUP );/* This is a best 1st approximation. ns to ms */ s->expected_downtime = max_downtime/1000000 ;
Signature · 1 line
1.7.10.4
PATCH RESEND v3 8/8 rdma: account for the time spent in MIG_STATE_SETUP through QMP
In reply to [email protected]From: "Michael R. Hines" <[email protected]>
Using the previous patches, we're now able to timestamp the SETUP state. Once we have this time, let the user know about it in the schema.
--- hmp.c | 4 ++++ include/migration/migration.h | 1 + migration.c | 9 +++++++++ qapi-schema.json | 9 ++++++++- 4 files changed, 22 insertions(+), 1 deletion(-)
hmp.c +4 -0
@@ -164,6 +164,10 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)monitor_printf (mon,"downtime: %" PRIu64" milliseconds\n" , info->downtime); } +if (info->has_setup_time) { +monitor_printf (mon,"setup: %" PRIu64" milliseconds\n" , + info->setup_time); + } }if (info->has_ram) {
include/migration/migration.h +1 -0
@@ -49,6 +49,7 @@ struct MigrationStateint64_t dirty_bytes_rate;bool enabled_capabilities[MIGRATION_CAPABILITY_MAX ];int64_t xbzrle_cache_size; +int64_t setup_time; };void process_incoming_migration (QEMUFile *f);
migration.c +9 -0
@@ -191,6 +191,7 @@ MigrationInfo *qmp_query_migrate(Error **errp)case MIG_STATE_SETUP : info->has_status = true; info->status =g_strdup ("setup" ); + info->has_total_time = false;break ;case MIG_STATE_ACTIVE : info->has_status = true;
@@ -200,6 +201,8 @@ MigrationInfo *qmp_query_migrate(Error **errp) - s->total_time; info->has_expected_downtime = true; info->expected_downtime = s->expected_downtime; + info->has_setup_time = true; + info->setup_time = s->setup_time; info->has_ram = true; info->ram =g_malloc0 (sizeof (*info->ram));
@@ -231,6 +234,8 @@ MigrationInfo *qmp_query_migrate(Error **errp) info->total_time = s->total_time; info->has_downtime = true; info->downtime = s->downtime; + info->has_setup_time = true; + info->setup_time = s->setup_time; info->has_ram = true; info->ram =g_malloc0 (sizeof (*info->ram));
@@ -521,6 +526,7 @@ static void *migration_thread(void *opaque) {MigrationState *s = opaque;int64_t initial_time =qemu_get_clock_ms (rt_clock); +int64_t setup_start =qemu_get_clock_ms (host_clock);int64_t initial_bytes =0 ;int64_t max_size =0 ;int64_t start_time = initial_time;
@@ -529,8 +535,11 @@ static void *migration_thread(void *opaque)DPRINTF ("beginning savevm\n" );qemu_savevm_state_begin (s->file, &s->params); + s->setup_time =qemu_get_clock_ms (host_clock) - setup_start;migrate_set_state (s,MIG_STATE_SETUP ,MIG_STATE_ACTIVE ); +DPRINTF ("setup complete\n" ); +while (s->state ==MIG_STATE_ACTIVE ) {int64_t current_time;uint64_t pending_size;
qapi-schema.json +8 -1
@@ -578,6 +578,12 @@ # expected downtime in milliseconds for the guest in last walk # of the dirty bitmap. (since 1.3) # +# @setup-time: #optional amount of setup time in milliseconds _before_ the +# iterations begin but _after_ the QMP command is issued. This is designed +# to provide an accounting of any activities (such as RDMA pinning) which +# may be expensive, but do not actually occur during the iterative +# migration rounds themselves. (since 1.6) +# # Since: 0.14.0 ## { 'type': 'MigrationInfo',
@@ -586,7 +592,8 @@ '*xbzrle-cache': 'XBZRLECacheStats', '*total-time': 'int', '*expected-downtime': 'int', - '*downtime': 'int'} } + '*downtime': 'int', + '*setup-time': 'int'} } ## # @query-migrate
Signature · 1 line
1.7.10.4