Skip to contentSkip to conversation

rdma: migration support

PATCH Superseded [email protected] 4 participants 56 messages Jun 25, 2013 – Jun 26, 2013 Kbuild

v11 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v11 cover rdma: migration support

From: "Michael R. Hines" <[email protected]>

Changes since v10: Detailed breakout of required state machine changes

- Fix tags. Only #13, 14, and 15 need reviews. Rest are completed.
- Patch #13: allow state transitions between other states besides ACTIVE
- Patch #14: introduce MIG_STATE_NONE and change MIG_STATE_SETUP transition
- Patch #15: account for the time spent in MIG_STATE_SETUP through QMP

Wiki: http://wiki.qemu.org/Features/RDMALiveMigration
Github: [email protected]:hinesmr/qemu.git

Here is a brief summary of total migration time and downtime using RDMA:

Using a 40gbps infiniband link performing a worst-case stress test, using an 8GB RAM virtual machine:
Using the following command:

$ apt-get install stress
$ stress --vm-bytes 7500M --vm 1 --vm-keep

RESULTS:

1. Migration throughput: 26 gigabits/second.
2. Downtime (stop time) varies between 15 and 100 milliseconds.

EFFECTS of memory registration on bulk phase round:

For example, in the same 8GB RAM example with all 8GB of memory in active use and the VM itself is completely idle using the same 40 gbps infiniband link:

1. x-rdma-pin-all disabled total time: approximately 7.5 seconds @ 9.5 Gbps
2. x-rdma-pin-all enabled total time: approximately 4 seconds @ 26 Gbps

These numbers would of course scale up to whatever size virtual machine you have to migrate using RDMA.

Enabling this feature does *not* have any measurable affect on migration *downtime*. This is because, without this feature, all of the memory will have already been registered already in advance during the bulk round and does not need to be re-registered during the successive iteration rounds.

----------------------------------------------------------------
Michael R. Hines (15):
rdma: add documentation
rdma: introduce qemu_update_position()
rdma: export yield_until_fd_readable()
rdma: export throughput w/ MigrationStats QMP
rdma: introduce qemu_file_mode_is_not_valid()
rdma: export qemu_fflush()
rdma: introduce ram_handle_compressed()
rdma: introduce qemu_ram_foreach_block()
rdma: new QEMUFileOps hooks
rdma: introduce capability x-rdma-pin-all
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                   |   69 +-
 configure                     |   29 +
 docs/rdma.txt                 |  415 ++++++
 exec.c                        |    9 +
 hmp.c                         |   12 +-
 include/block/coroutine.h     |    6 +
 include/exec/cpu-common.h     |    5 +
 include/migration/migration.h |   32 +
 include/migration/qemu-file.h |   32 +
 migration-rdma.c              | 2819 +++++++++++++++++++++++++++++++++++++++++
 migration.c                   |   64 +-
 qapi-schema.json              |   21 +-
 qemu-coroutine-io.c           |   23 +
 savevm.c                      |  114 +-
 15 files changed, 3589 insertions(+), 62 deletions(-)
 create mode 100644 docs/rdma.txt
 create mode 100644 migration-rdma.c
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH v11 1/15 rdma: add documentation

From: "Michael R. Hines" <[email protected]>

docs/rdma.txt contains full documentation, wiki links, github url and contact information.

---
 docs/rdma.txt |  415 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 415 insertions(+)
 create mode 100644 docs/rdma.txt
docs/rdma.txt new file +415 -0
new file mode 100644
index 0000000..09d36ef
@@ -0,0 +1,415 @@
+(RDMA: Remote Direct Memory Access)
+RDMA Live Migration Specification, Version # 1
+==============================================
+Wiki: http://wiki.qemu.org/Features/RDMALiveMigration
+Github: [email protected]:hinesmr/qemu.git, 'rdma' branch
+
+Copyright (C) 2013 Michael R. Hines <[email protected]>
+
+An *exhaustive* paper (2010) shows additional performance details
+linked on the QEMU wiki above.
+
+Contents:
+=========
+* Introduction
+* Before running
+* Running
+* Performance
+* RDMA Migration Protocol Description
+* Versioning and Capabilities
+* QEMUFileRDMA Interface
+* Migration of pc.ram
+* Error handling
+* TODO
+
+Introduction:
+=============
+
+RDMA helps make your migration more deterministic under heavy load because
+of the significantly lower latency and higher throughput over TCP/IP. This is
+because the RDMA I/O architecture reduces the number of interrupts and
+data copies by bypassing the host networking stack. In particular, a TCP-based
+migration, under certain types of memory-bound workloads, may take a more
+unpredicatable amount of time to complete the migration if the amount of
+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
+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.
+
+Refer to openfabrics.org or your respective RDMA hardware vendor for
+an understanding on how to verify that you have the OFED software stack
+installed in your environment. You should be able to successfully link
+against the "librdmacm" and "libibverbs" libraries and development headers
+for a working build of QEMU to run successfully using RDMA Migration.
+
+BEFORE RUNNING:
+===============
+
+Use of RDMA during migration requires pinning and registering memory
+with the hardware. This means that memory must be physically resident
+before the hardware can transmit that memory to another machine.
+If this is not acceptable for your application or product, then the use
+of RDMA migration may in fact be harmful to co-located VMs or other
+software on the machine if there is not sufficient memory available to
+relocate the entire footprint of the virtual machine. If so, then the
+use of RDMA is discouraged and it is recommended to use standard TCP migration.
+
+Experimental: Next, decide if you want dynamic page registration.
+For example, if you have an 8GB RAM virtual machine, but only 1GB
+is in active use, then enabling this feature will cause all 8GB to
+be pinned and resident in memory. This feature mostly affects the
+bulk-phase round of the migration and can be enabled for extremely
+high-performance RDMA hardware using the following command:
+
+QEMU Monitor Command:
+$ migrate_set_capability x-rdma-pin-all on # disabled by default
+
+Performing this action will cause all 8GB to be pinned, so if that's
+not what you want, then please ignore this step altogether.
+
+On the other hand, this will also significantly speed up the bulk round
+of the migration, which can greatly reduce the "total" time of your migration.
+Example performance of this using an idle VM in the previous example
+can be found in the "Performance" section.
+
+Note: for very large virtual machines (hundreds of GBs), pinning all 
+*all* of the memory of your virtual machine in the kernel is very expensive 
+may extend the initial bulk iteration time by many seconds,
+and thus extending the total migration time. However, this will not
+affect the determinism or predictability of your migration you will
+still gain from the benefits of advanced pinning with RDMA.
+
+RUNNING:
+========
+
+First, set the migration speed to match your hardware's capabilities:
+
+QEMU Monitor Command:
+$ migrate_set_speed 40g # or whatever is the MAX of your RDMA device
+
+Next, on the destination machine, add the following to the QEMU command line:
+
+qemu ..... -incoming x-rdma:host:port
+
+Finally, perform the actual migration on the source machine:
+
+QEMU Monitor Command:
+$ migrate -d x-rdma:host:port
+
+PERFORMANCE
+===========
+
+Here is a brief summary of total migration time and downtime using RDMA:
+Using a 40gbps infiniband link performing a worst-case stress test,
+using an 8GB RAM virtual machine:
+
+Using the following command:
+$ apt-get install stress
+$ stress --vm-bytes 7500M --vm 1 --vm-keep
+
+1. Migration throughput: 26 gigabits/second.
+2. Downtime (stop time) varies between 15 and 100 milliseconds.
+
+EFFECTS of memory registration on bulk phase round:
+
+For example, in the same 8GB RAM example with all 8GB of memory in
+active use and the VM itself is completely idle using the same 40 gbps
+infiniband link:
+
+1. x-rdma-pin-all disabled total time: approximately 7.5 seconds @ 9.5 Gbps
+2. x-rdma-pin-all enabled total time: approximately 4 seconds @ 26 Gbps
+
+These numbers would of course scale up to whatever size virtual machine
+you have to migrate using RDMA.
+
+Enabling this feature does *not* have any measurable affect on
+migration *downtime*. This is because, without this feature, all of the
+memory will have already been registered already in advance during
+the bulk round and does not need to be re-registered during the successive
+iteration rounds.
+
+RDMA Protocol Description:
+==========================
+
+Migration with RDMA is separated into two parts:
+
+1. The transmission of the pages using RDMA
+2. Everything else (a control channel is introduced)
+
+"Everything else" is transmitted using a formal
+protocol now, consisting of infiniband SEND messages.
+
+An infiniband SEND message is the standard ibverbs
+message used by applications of infiniband hardware.
+The only difference between a SEND message and an RDMA
+message is that SEND messages cause notifications
+to be posted to the completion queue (CQ) on the
+infiniband receiver side, whereas RDMA messages (used
+for pc.ram) do not (to behave like an actual DMA).
+
+Messages in infiniband require two things:
+
+1. registration of the memory that will be transmitted
+2. (SEND only) work requests to be posted on both
+   sides of the network before the actual transmission
+   can occur.
+
+RDMA messages are much easier to deal with. Once the memory
+on the receiver side is registered and pinned, we're
+basically done. All that is required is for the sender
+side to start dumping bytes onto the link.
+
+(Memory is not released from pinning until the migration
+completes, given that RDMA migrations are very fast.)
+
+SEND messages require more coordination because the
+receiver must have reserved space (using a receive
+work request) on the receive queue (RQ) before QEMUFileRDMA
+can start using them to carry all the bytes as
+a control transport for migration of device state.
+
+To begin the migration, the initial connection setup is
+as follows (migration-rdma.c):
+
+1. Receiver and Sender are started (command line or libvirt):
+2. Both sides post two RQ work requests
+3. Receiver does listen()
+4. Sender does connect()
+5. Receiver accept()
+6. Check versioning and capabilities (described later)
+
+At this point, we define a control channel on top of SEND messages
+which is described by a formal protocol. Each SEND message has a
+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)
+
+The 'Repeat' field is here to support future multiple page registrations
+in a single message without any need to change the protocol itself
+so that the protocol is compatible against multiple versions of QEMU.
+Version #1 requires that all server implementations of the protocol must
+check this field and register all requests found in the array of commands located
+in the data portion and return an equal number of results in the response.
+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)
+
+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
+one command, then the 'repeat' field will be greater than 1.
+
+After connection setup, message 5 & 6 are used to exchange ram block
+information and optionally pin all the memory if requested by the user.
+
+After ram block exchange is completed, we have two protocol-level
+functions, responsible for communicating control-channel commands
+using the above list of values:
+
+Logically:
+
+qemu_rdma_exchange_recv(header, expected command type)
+
+1. We transmit a READY command to let the sender know that
+   we are *ready* to receive some data bytes on the control channel.
+2. Before attempting to receive the expected command, we post another
+   RQ work request to replace the one we just used up.
+3. Block on a CQ event channel and wait for the SEND to arrive.
+4. When the send arrives, librdmacm will unblock us.
+5. Verify that the command-type and version received matches the one we expected.
+
+qemu_rdma_exchange_send(header, data, optional response header & data):
+
+1. Block on the CQ event channel waiting for a READY command
+   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
+   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
+   to replace the one we just used up.
+4. Now, we can actually post the work request to SEND
+   the requested command type of the header we were asked for.
+5. Optionally, if we are expecting a response (as before),
+   we block again and wait for that response using the additional
+   work request we previously posted. (This is used to carry
+   'Register result' commands #6 back to the sender which
+   hold the rkey need to perform RDMA. Note that the virtual address
+   corresponding to this rkey was already exchanged at the beginning
+   of the connection (described below).
+
+All of the remaining command types (not including 'ready')
+described above all use the aformentioned two functions to do the hard work:
+
+1. After connection setup, RAMBlock information is exchanged using
+   this protocol before the actual migration begins. This information includes
+   a description of each RAMBlock on the server side as well as the virtual addresses
+   and lengths of each RAMBlock. This is used by the client to determine the
+   start and stop locations of chunks and how to register them dynamically
+   before performing the RDMA operations.
+2. During runtime, once a 'chunk' becomes full of pages ready to
+   be sent with RDMA, the registration commands are used to ask the
+   other side to register the memory for this chunk and respond
+   with the result (rkey) of the registration.
+3. Also, the QEMUFile interfaces also call these functions (described below)
+   when transmitting non-live state, such as devices or to send
+   its own protocol information during the migration process.
+4. Finally, zero pages are only checked if a page has not yet been registered
+   using chunk registration (or not checked at all and unconditionally
+   written if chunk registration is disabled. This is accomplished using
+   the "Compress" command listed above. If the page *has* been registered
+   then we check the entire chunk for zero. Only if the entire chunk is
+   zero, then we send a compress command to zap the page on the other side.
+
+Versioning and Capabilities
+===========================
+Current version of the protocol is version #1.
+
+The same version applies to both for protocol traffic and capabilities
+negotiation. (i.e. There is only one version number that is referred to
+by all communication).
+
+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
+
+There is no data portion of this header right now, so there is
+no length field. The maximum size of the 'private data' section
+is only 192 bytes per the Infiniband specification, so it's not
+very useful for data anyway. This structure needs to remain small.
+
+This private data area is a convenient place to check for protocol
+versioning because the user does not need to register memory to
+transmit a few bytes of version information.
+
+This is also a convenient place to negotiate capabilities
+(like dynamic page registration).
+
+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
+
+Finally: Negotiation happens with the Flags field: If the primary-VM
+sets a flag, but the destination does not support this capability, it
+will return a zero-bit for that flag and the primary-VM will understand
+that as not being an available capability and will thus disable that
+capability on the primary-VM side.
+
+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)
+
+These two functions are very short and simply use the protocol
+describe above to deliver bytes without changing the upper-level
+users of QEMUFile that depend on a bytestream abstraction.
+
+Finally, how do we handoff the actual bytes to get_buffer()?
+
+Again, because we're trying to "fake" a bytestream abstraction
+using an analogy not unlike individual UDP frames, we have
+to hold on to the bytes received from control-channel's SEND
+messages in memory.
+
+Each time we receive a complete "QEMU File" control-channel
+message, the bytes from SEND are copied into a small local holding area.
+
+Then, we return the number of bytes requested by get_buffer()
+and leave the remaining bytes in the holding area until get_buffer()
+comes around for another pass.
+
+If the buffer is empty, then we follow the same steps
+listed above and issue another "QEMU File" protocol command,
+asking for a new SEND message to re-fill the buffer.
+
+Migration of pc.ram:
+====================
+
+At the beginning of the migration, (migration-rdma.c),
+the sender and the receiver populate the list of RAMBlocks
+to be registered with each other into a structure.
+Then, using the aforementioned protocol, they exchange a
+description of these blocks with each other, to be used later
+during the iteration of main memory. This description includes
+a list of all the RAMBlocks, their offsets and lengths, virtual
+addresses and possibly includes pre-registered RDMA keys in case dynamic
+page registration was disabled on the server-side, otherwise not.
+
+Main memory is not migrated with the aforementioned protocol,
+but is instead migrated with normal RDMA Write operations.
+
+Pages are migrated in "chunks" (hard-coded to 1 Megabyte right now).
+Chunk size is not dynamic, but it could be in a future implementation.
+There's nothing to indicate that this is useful right now.
+
+When a chunk is full (or a flush() occurs), the memory backed by
+the chunk is registered with librdmacm is pinned in memory on
+both sides using the aforementioned protocol.
+After pinning, an RDMA Write is generated and transmitted
+for the entire chunk.
+
+Chunks are also transmitted in batches: This means that we
+do not request that the hardware signal the completion queue
+for the completion of *every* chunk. The current batch size
+is about 64 chunks (corresponding to 64 MB of memory).
+Only the last chunk in a batch must be signaled.
+This helps keep everything as asynchronous as possible
+and helps keep the hardware busy performing RDMA operations.
+
+Error-handling:
+===============
+
+Infiniband has what is called a "Reliable, Connected"
+link (one of 4 choices). This is the mode in which
+we use for RDMA migration.
+
+If a *single* message fails,
+the decision is to abort the migration entirely and
+cleanup all the RDMA descriptors and unregister all
+the memory.
+
+After cleanup, the Virtual Machine is returned to normal
+operation the same way that would happen if the TCP
+socket is broken during a non-RDMA based migration.
+
+TODO:
+=====
+1. 'migrate x-rdma:host:port' and '-incoming x-rdma' options will be
+   renamed to 'rdma' after the experimental phase of this work has
+   completed upstream.
+2. Currently, 'ulimit -l' mlock() limits as well as cgroups swap limits
+   are not compatible with infinband memory pinning and will result in
+   an aborted migration (but with the source VM left unaffected).
+3. Use of the recent /proc/<pid>/pagemap would likely speed up
+   the use of KSM and ballooning while using RDMA.
+4. Also, some form of balloon-device usage tracking would also
+   help alleviate some issues.
Signature · 1 line
1.7.10.4
Reviewed-by on v11 1/15
#2 lore raw

Re: [Qemu-devel] [PATCH v11 01/15] rdma: add documentation

Quoted 10 lines · [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

docs/rdma.txt contains full documentation, wiki links, github url and contact information.

#3 lore raw

PATCH v11 2/15 rdma: introduce qemu_update_position()

In reply to [email protected]

From: "Michael R. Hines" <[email protected]>

RDMA writes happen asynchronously, and thus the performance accounting also needs to be able to occur asynchronously. This allows anybody to call into savevm.c to update both f->pos as well as into arch_init.c to update the acct_info structure with up-to-date values when the RDMA transfer actually completes.

---
 arch_init.c                   |   12 ++++++++++++
 include/migration/migration.h |    2 ++
 include/migration/qemu-file.h |    1 +
 savevm.c                      |    5 +++++
 4 files changed, 20 insertions(+)
arch_init.c +12 -0
index a8b91ee..494a14f 100644
@@ -498,6 +498,18 @@ static int ram_save_block(QEMUFile *f, bool last_stage)
 
 static uint64_t bytes_transferred;
 
+void acct_update_position(QEMUFile *f, size_t size, bool zero)
+{
+    uint64_t pages = size / TARGET_PAGE_SIZE;
+    if (zero) {
+        acct_info.dup_pages += pages;
+    } else {
+        acct_info.norm_pages += pages;
+        bytes_transferred += size;
+        qemu_update_position(f, size);
+    }
+}
+
 static ram_addr_t ram_save_remaining(void)
 {
     return migration_dirty_pages;
include/migration/migration.h +2 -0
index e2acec6..0be28a2 100644
@@ -92,6 +92,8 @@ uint64_t ram_bytes_remaining(void);
 uint64_t ram_bytes_transferred(void);
 uint64_t ram_bytes_total(void);
 
+void acct_update_position(QEMUFile *f, size_t size, bool zero);
+
 extern SaveVMHandlers savevm_ram_handlers;
 
 uint64_t dup_mig_bytes_transferred(void);
include/migration/qemu-file.h +1 -0
index 7519464..8fab0dd 100644
@@ -93,6 +93,7 @@ void qemu_put_be32(QEMUFile *f, unsigned int v);
 void qemu_put_be64(QEMUFile *f, uint64_t v);
 int qemu_get_buffer(QEMUFile *f, uint8_t *buf, int size);
 int qemu_get_byte(QEMUFile *f);
+void qemu_update_position(QEMUFile *f, size_t size);
 
 static inline unsigned int qemu_get_ubyte(QEMUFile *f)
 {
savevm.c +5 -0
index 48cc2a9..9b5577e 100644
@@ -671,6 +671,11 @@ int qemu_get_fd(QEMUFile *f)
     return -1;
 }
 
+void qemu_update_position(QEMUFile *f, size_t size)
+{
+    f->pos += size;
+}
+
 /** Closes the file
  *
  * Returns negative error value if any error happened on previous operations or
Signature · 1 line
1.7.10.4
Reviewed-by on v11 2/15
#4 lore raw

Re: [Qemu-devel] [PATCH v11 02/15] rdma: introduce qemu_update_position()

Quoted 11 lines · [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

RDMA writes happen asynchronously, and thus the performance accounting also needs to be able to occur asynchronously. This allows anybody to call into savevm.c to update both f->pos as well as into arch_init.c to update the acct_info structure with up-to-date values when the RDMA transfer actually completes.

#5 lore raw

PATCH v11 3/15 rdma: export yield_until_fd_readable()

In reply to [email protected]

From: "Michael R. Hines" <[email protected]>

The RDMA event channel can be made non-blocking just like a TCP socket. Exporting this function allows us to yield so that the QEMU monitor remains available.

---
 include/block/coroutine.h |    6 ++++++
 qemu-coroutine-io.c       |   23 +++++++++++++++++++++++
 savevm.c                  |   28 ----------------------------
 3 files changed, 29 insertions(+), 28 deletions(-)
include/block/coroutine.h +6 -0
index a978162..377805a 100644
@@ -209,4 +209,10 @@ void qemu_co_rwlock_unlock(CoRwlock *lock);
  */
 void coroutine_fn co_sleep_ns(QEMUClock *clock, int64_t ns);
 
+/**
+ * Yield until a file descriptor becomes readable
+ *
+ * Note that this function clobbers the handlers for the file descriptor.
+ */
+void coroutine_fn yield_until_fd_readable(int fd);
 #endif /* QEMU_COROUTINE_H */
qemu-coroutine-io.c +23 -0
index e8ad1a4..c4df35a 100644
@@ -63,3 +63,26 @@ qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool do_send)
     struct iovec iov = { .iov_base = buf, .iov_len = bytes };
     return qemu_co_sendv_recvv(sockfd, &iov, 1, 0, bytes, do_send);
 }
+
+typedef struct {
+    Coroutine *co;
+    int fd;
+} FDYieldUntilData;
+
+static void fd_coroutine_enter(void *opaque)
+{
+    FDYieldUntilData *data = opaque;
+    qemu_set_fd_handler(data->fd, NULL, NULL, NULL);
+    qemu_coroutine_enter(data->co, NULL);
+}
+
+void coroutine_fn yield_until_fd_readable(int fd)
+{
+    FDYieldUntilData data;
+
+    assert(qemu_in_coroutine());
+    data.co = qemu_coroutine_self();
+    data.fd = fd;
+    qemu_set_fd_handler(fd, fd_coroutine_enter, NULL, &data);
+    qemu_coroutine_yield();
+}
savevm.c +0 -28
index 9b5577e..e35c7a4 100644
@@ -149,34 +149,6 @@ typedef struct QEMUFileSocket
     QEMUFile *file;
 } QEMUFileSocket;
 
-typedef struct {
-    Coroutine *co;
-    int fd;
-} FDYieldUntilData;
-
-static void fd_coroutine_enter(void *opaque)
-{
-    FDYieldUntilData *data = opaque;
-    qemu_set_fd_handler(data->fd, NULL, NULL, NULL);
-    qemu_coroutine_enter(data->co, NULL);
-}
-
-/**
- * Yield until a file descriptor becomes readable
- *
- * Note that this function clobbers the handlers for the file descriptor.
- */
-static void coroutine_fn yield_until_fd_readable(int fd)
-{
-    FDYieldUntilData data;
-
-    assert(qemu_in_coroutine());
-    data.co = qemu_coroutine_self();
-    data.fd = fd;
-    qemu_set_fd_handler(fd, fd_coroutine_enter, NULL, &data);
-    qemu_coroutine_yield();
-}
-
 static ssize_t socket_writev_buffer(void *opaque, struct iovec *iov, int iovcnt,
                                     int64_t pos)
 {
Signature · 1 line
1.7.10.4
Reviewed-by on v11 3/15
#6 lore raw

Re: [Qemu-devel] [PATCH v11 03/15] rdma: export yield_until_fd_readable()

Quoted 11 lines · [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

The RDMA event channel can be made non-blocking just like a TCP socket. Exporting this function allows us to yield so that the QEMU monitor remains available.

#7 lore raw

PATCH v11 4/15 rdma: export throughput w/ MigrationStats QMP

In reply to [email protected]

From: "Michael R. Hines" <[email protected]>

This exposes throughput (in megabits/sec) through QMP.

---
 hmp.c                         |    8 ++++++--
 include/migration/migration.h |    1 +
 migration.c                   |    6 ++++++
 qapi-schema.json              |    5 ++++-
 4 files changed, 17 insertions(+), 3 deletions(-)
hmp.c +6 -2
index 494a9aa..a3c6b55 100644
@@ -154,8 +154,10 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
 
     if (info->has_status) {
         monitor_printf(mon, "Migration status: %s\n", info->status);
-        monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
-                       info->total_time);
+        if (info->has_total_time) {
+            monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
+                           info->total_time);
+        }
         if (info->has_expected_downtime) {
             monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
                            info->expected_downtime);
@@ -169,6 +171,8 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
     if (info->has_ram) {
         monitor_printf(mon, "transferred ram: %" PRIu64 " kbytes\n",
                        info->ram->transferred >> 10);
+        monitor_printf(mon, "throughput: %0.2f mbps\n",
+                       info->ram->mbps);
         monitor_printf(mon, "remaining ram: %" PRIu64 " kbytes\n",
                        info->ram->remaining >> 10);
         monitor_printf(mon, "total ram: %" PRIu64 " kbytes\n",
include/migration/migration.h +1 -0
index 0be28a2..535e844 100644
@@ -40,6 +40,7 @@ struct MigrationState
 
     int state;
     MigrationParams params;
+    double mbps;
     int64_t total_time;
     int64_t downtime;
     int64_t expected_downtime;
migration.c +6 -0
index 058f9e6..441a3b2 100644
@@ -66,6 +66,7 @@ MigrationState *migrate_get_current(void)
         .state = MIG_STATE_SETUP,
         .bandwidth_limit = MAX_THROTTLE,
         .xbzrle_cache_size = DEFAULT_MIGRATE_CACHE_SIZE,
+        .mbps = -1,
     };
 
     return &current_migration;
@@ -201,6 +202,7 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         info->ram->normal = norm_mig_pages_transferred();
         info->ram->normal_bytes = norm_mig_bytes_transferred();
         info->ram->dirty_pages_rate = s->dirty_pages_rate;
+        info->ram->mbps = s->mbps;
 
         if (blk_mig_active()) {
             info->has_disk = true;
@@ -230,6 +232,7 @@ MigrationInfo *qmp_query_migrate(Error **errp)
         info->ram->skipped = skipped_mig_pages_transferred();
         info->ram->normal = norm_mig_pages_transferred();
         info->ram->normal_bytes = norm_mig_bytes_transferred();
+        info->ram->mbps = s->mbps;
         break;
     case MIG_STATE_ERROR:
         info->has_status = true;
@@ -543,6 +546,9 @@ static void *migration_thread(void *opaque)
             double bandwidth = transferred_bytes / time_spent;
             max_size = bandwidth * migrate_max_downtime() / 1000000;
 
+            s->mbps = time_spent ? (((double) transferred_bytes * 8.0) /
+                    ((double) time_spent / 1000.0)) / 1000.0 / 1000.0 : -1;
+
             DPRINTF("transferred %" PRIu64 " time_spent %" PRIu64
                     " bandwidth %g max_size %" PRId64 "\n",
                     transferred_bytes, time_spent, bandwidth, max_size);
qapi-schema.json +4 -1
index 6cc07c2..78da557 100644
@@ -513,12 +513,15 @@
 # @dirty-pages-rate: number of pages dirtied by second by the
 #        guest (since 1.3)
 #
+# @mbps: throughput in megabits/sec. (since 1.6)
+#
 # Since: 0.14.0
 ##
 { 'type': 'MigrationStats',
   'data': {'transferred': 'int', 'remaining': 'int', 'total': 'int' ,
            'duplicate': 'int', 'skipped': 'int', 'normal': 'int',
-           'normal-bytes': 'int', 'dirty-pages-rate' : 'int' } }
+           'normal-bytes': 'int', 'dirty-pages-rate' : 'int',
+           'mbps' : 'number' } }
 
 ##
 # @XBZRLECacheStats
Signature · 1 line
1.7.10.4
Reviewed-by on v11 4/15
#8 lore raw

Re: [Qemu-devel] [PATCH v11 04/15] rdma: export throughput w/ MigrationStats QMP

Quoted 12 lines · [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

This exposes throughput (in megabits/sec) through QMP.

hmp.c +0 -0
@@ -154,8 +154,10 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
 
     if (info->has_status) {

hmp.c void hmp_info_migrate(Monitor *mon, const QDict *qdict) · line 163

Quoted 10 lines
hmp.c +4 -2
         monitor_printf(mon, "Migration status: %s\n", info->status);
-        monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
-                       info->total_time);
+        if (info->has_total_time) {
+            monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
+                           info->total_time);
+        }
         if (info->has_expected_downtime) {
             monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
                            info->expected_downtime);

This chunk don't belong to this patch.

for the rest:

#9 lore raw

Re: [Qemu-devel] [PATCH v11 04/15] rdma: export throughput w/ MigrationStats QMP

Quoted 25 lines · Juan Quintela
Quoted 12 lines · [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

This exposes throughput (in megabits/sec) through QMP.

hmp.c +0 -0
@@ -154,8 +154,10 @@ void hmp_info_migrate(Monitor *mon, const QDict *qdict)
 
      if (info->has_status) {

hmp.c void hmp_info_migrate(Monitor *mon, const QDict *qdict) · line 163

Quoted 10 lines
hmp.c +4 -2
          monitor_printf(mon, "Migration status: %s\n", info->status);
-        monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
-                       info->total_time);
+        if (info->has_total_time) {
+            monitor_printf(mon, "total time: %" PRIu64 " milliseconds\n",
+                           info->total_time);
+        }
          if (info->has_expected_downtime) {
              monitor_printf(mon, "expected downtime: %" PRIu64 " milliseconds\n",
                             info->expected_downtime);

This chunk don't belong to this patch.

Quoted 4 lines

for the rest:

Acknowledged - will drop the hunk in the next version.

- Michael

#10 lore raw

PATCH v11 5/15 rdma: introduce qemu_file_mode_is_not_valid()

In reply to [email protected]

From: "Michael R. Hines" <[email protected]>

QEMUFileRDMA also has read and write modes. This function is now shared to reduce code duplication.

---
 include/migration/qemu-file.h |    1 +
 savevm.c                      |   20 +++++++++++++-------
 2 files changed, 14 insertions(+), 7 deletions(-)
include/migration/qemu-file.h +1 -0
index 8fab0dd..dd3fd51 100644
@@ -80,6 +80,7 @@ void qemu_put_byte(QEMUFile *f, int v);
  * The buffer should be available till it is sent asynchronously.
  */
 void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, int size);
+bool qemu_file_mode_is_not_valid(const char *mode);
 
 static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v)
 {
savevm.c +13 -7
index e35c7a4..67ddf06 100644
@@ -449,14 +449,23 @@ static const QEMUFileOps socket_write_ops = {
     .close =      socket_close
 };
 
-QEMUFile *qemu_fopen_socket(int fd, const char *mode)
+bool qemu_file_mode_is_not_valid(const char *mode)
 {
-    QEMUFileSocket *s;
-
     if (mode == NULL ||
         (mode[0] != 'r' && mode[0] != 'w') ||
         mode[1] != 'b' || mode[2] != 0) {
         fprintf(stderr, "qemu_fopen: Argument validity check failed\n");
+        return true;
+    }
+
+    return false;
+}
+
+QEMUFile *qemu_fopen_socket(int fd, const char *mode)
+{
+    QEMUFileSocket *s;
+
+    if (qemu_file_mode_is_not_valid(mode)) {
         return NULL;
     }
 
@@ -475,10 +484,7 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode)
 {
     QEMUFileStdio *s;
 
-    if (mode == NULL ||
-	(mode[0] != 'r' && mode[0] != 'w') ||
-	mode[1] != 'b' || mode[2] != 0) {
-        fprintf(stderr, "qemu_fopen: Argument validity check failed\n");
+    if (qemu_file_mode_is_not_valid(mode)) {
         return NULL;
     }
 
Signature · 1 line
1.7.10.4
Reviewed-by on v11 5/15
#11 lore raw

Re: [Qemu-devel] [PATCH v11 05/15] rdma: introduce qemu_file_mode_is_not_valid()

Quoted 10 lines · [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

QEMUFileRDMA also has read and write modes. This function is now shared to reduce code duplication.

#12 lore raw

PATCH v11 6/15 rdma: export qemu_fflush()

In reply to [email protected]

From: "Michael R. Hines" <[email protected]>

RDMA uses this to flush the control channel before sending its own message to handle page registrations.

---
 include/migration/qemu-file.h |    1 +
 savevm.c                      |    2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
include/migration/qemu-file.h +1 -0
index dd3fd51..37d1604 100644
@@ -112,6 +112,7 @@ void qemu_file_reset_rate_limit(QEMUFile *f);
 void qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);
 int64_t qemu_file_get_rate_limit(QEMUFile *f);
 int qemu_file_get_error(QEMUFile *f);
+void qemu_fflush(QEMUFile *f);
 
 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
 {
savevm.c +1 -1
index 67ddf06..26d5607 100644
@@ -589,7 +589,7 @@ static inline bool qemu_file_is_writable(QEMUFile *f)
  * If there is writev_buffer QEMUFileOps it uses it otherwise uses
  * put_buffer ops.
  */
-static void qemu_fflush(QEMUFile *f)
+void qemu_fflush(QEMUFile *f)
 {
     ssize_t ret = 0;
 
Signature · 1 line
1.7.10.4
Reviewed-by on v11 6/15
#13 lore raw

Re: [Qemu-devel] [PATCH v11 06/15] rdma: export qemu_fflush()

Quoted 10 lines · [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

RDMA uses this to flush the control channel before sending its own message to handle page registrations.

#14 lore raw

PATCH v11 7/15 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                   |   24 ++++++++++++++++--------
 include/migration/migration.h |    2 ++
 2 files changed, 18 insertions(+), 8 deletions(-)
arch_init.c +16 -8
index 494a14f..00bc3a9 100644
@@ -782,6 +782,21 @@ 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)
+{
+    memset(host, ch, TARGET_PAGE_SIZE);
+#ifndef _WIN32
+    if (ch == 0 && (!kvm_enabled() || kvm_has_sync_mmu()) &&
+                            getpagesize() <= TARGET_PAGE_SIZE) {
+        qemu_madvise(host, size, QEMU_MADV_DONTNEED);
+    }
+#endif
+}
+
 static int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
     ram_addr_t addr;
@@ -849,14 +864,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
             }
 
             ch = qemu_get_byte(f);
-            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
index 535e844..8d9cbd1 100644
@@ -108,6 +108,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
Reviewed-by on v11 7/15
#15 lore raw

Re: [Qemu-devel] [PATCH v11 07/15] rdma: introduce ram_handle_compressed()

Quoted 10 lines · [email protected] wrote:

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.

#16 lore raw

PATCH v11 8/15 rdma: introduce qemu_ram_foreach_block()

In reply to [email protected]

From: "Michael R. Hines" <[email protected]>

This is used during RDMA initialization in order to transmit a description of all the RAM blocks to the peer for later dynamic chunk registration purposes.

---
 exec.c                    |    9 +++++++++
 include/exec/cpu-common.h |    5 +++++
 2 files changed, 14 insertions(+)
exec.c +9 -0
index 0b0118b..2e6fc00 100644
@@ -2630,3 +2630,12 @@ bool cpu_physical_memory_is_io(hwaddr phys_addr)
              memory_region_is_romd(mr));
 }
 #endif
+
+void qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque)
+{
+    RAMBlock *block;
+
+    QTAILQ_FOREACH(block, &ram_list.blocks, next) {
+        func(block->host, block->offset, block->length, opaque);
+    }
+}
include/exec/cpu-common.h +5 -0
index e061e21..92a4223 100644
@@ -113,6 +113,11 @@ void cpu_physical_memory_write_rom(hwaddr addr,
 extern struct MemoryRegion io_mem_rom;
 extern struct MemoryRegion io_mem_notdirty;
 
+typedef void (RAMBlockIterFunc)(void *host_addr,
+    ram_addr_t offset, ram_addr_t length, void *opaque);
+
+void qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque);
+
 #endif
 
 #endif /* !CPU_COMMON_H */
Signature · 1 line
1.7.10.4
Reviewed-by on v11 8/15
#17 lore raw

Re: [Qemu-devel] [PATCH v11 08/15] rdma: introduce qemu_ram_foreach_block()

Quoted 11 lines · [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

This is used during RDMA initialization in order to transmit a description of all the RAM blocks to the peer for later dynamic chunk registration purposes.

#18 lore raw

PATCH v11 9/15 rdma: new QEMUFileOps hooks

In reply to [email protected]

From: "Michael R. Hines" <[email protected]>

These are the prototypes and implementation of new hooks that RDMA takes advantage of to perform dynamic page registration.

An optional hook is also introduced for a custom function to be able to override the default save_page function.

Also included are the prototypes and accessor methods used by arch_init.c which invoke funtions inside savevm.c to call out to the hooks that may or may not have been overridden inside of QEMUFileOps.

---
 include/migration/migration.h |   20 ++++++++++++++
 include/migration/qemu-file.h |   29 ++++++++++++++++++++
 savevm.c                      |   59 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+)
include/migration/migration.h +20 -0
index 8d9cbd1..7b153d7 100644
@@ -21,6 +21,7 @@
 #include "qapi/error.h"
 #include "migration/vmstate.h"
 #include "qapi-types.h"
+#include "exec/cpu-common.h"
 
 struct MigrationParams {
     bool blk;
@@ -132,4 +133,23 @@ int migrate_use_xbzrle(void);
 int64_t migrate_xbzrle_cache_size(void);
 
 int64_t xbzrle_cache_resize(int64_t new_size);
+
+void ram_control_before_iterate(QEMUFile *f, uint64_t flags);
+void ram_control_after_iterate(QEMUFile *f, uint64_t flags);
+void ram_control_load_hook(QEMUFile *f, uint64_t flags);
+
+/* Whenever this is found in the data stream, the flags
+ * will be passed to ram_control_load_hook in the incoming-migration
+ * side. This lets before_ram_iterate/after_ram_iterate add
+ * transport-specific sections to the RAM migration data.
+ */
+#define RAM_SAVE_FLAG_HOOK     0x80
+
+#define RAM_SAVE_CONTROL_NOT_SUPP -1000
+#define RAM_SAVE_CONTROL_DELAYED  -2000
+
+size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,
+                             ram_addr_t offset, size_t size,
+                             int *bytes_sent);
+
 #endif
include/migration/qemu-file.h +29 -0
index 37d1604..0f757fb 100644
@@ -23,6 +23,7 @@
  */
 #ifndef QEMU_FILE_H
 #define QEMU_FILE_H 1
+#include "exec/cpu-common.h"
 
 /* This function writes a chunk of data to a file at the given position.
  * The pos argument can be ignored if the file is only being used for
@@ -57,12 +58,40 @@ typedef int (QEMUFileGetFD)(void *opaque);
 typedef ssize_t (QEMUFileWritevBufferFunc)(void *opaque, struct iovec *iov,
                                            int iovcnt, int64_t pos);
 
+/*
+ * This function provides hooks around different
+ * stages of RAM migration.
+ */
+typedef int (QEMURamHookFunc)(QEMUFile *f, void *opaque, uint64_t flags);
+
+/*
+ * Constants used by ram_control_* hooks
+ */
+#define RAM_CONTROL_SETUP    0
+#define RAM_CONTROL_ROUND    1
+#define RAM_CONTROL_HOOK     2
+#define RAM_CONTROL_FINISH   3
+
+/*
+ * This function allows override of where the RAM page
+ * is saved (such as RDMA, for example.)
+ */
+typedef size_t (QEMURamSaveFunc)(QEMUFile *f, void *opaque,
+                               ram_addr_t block_offset,
+                               ram_addr_t offset,
+                               size_t size,
+                               int *bytes_sent);
+
 typedef struct QEMUFileOps {
     QEMUFilePutBufferFunc *put_buffer;
     QEMUFileGetBufferFunc *get_buffer;
     QEMUFileCloseFunc *close;
     QEMUFileGetFD *get_fd;
     QEMUFileWritevBufferFunc *writev_buffer;
+    QEMURamHookFunc *before_ram_iterate;
+    QEMURamHookFunc *after_ram_iterate;
+    QEMURamHookFunc *hook_ram_load;
+    QEMURamSaveFunc *save_page;
 } QEMUFileOps;
 
 QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops);
savevm.c +59 -0

65 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#19 lore raw

Re: [Qemu-devel] [PATCH v11 09/15] rdma: new QEMUFileOps hooks

Quoted 13 lines · [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

These are the prototypes and implementation of new hooks that RDMA takes advantage of to perform dynamic page registration.

An optional hook is also introduced for a custom function to be able to override the default save_page function.

Also included are the prototypes and accessor methods used by arch_init.c which invoke funtions inside savevm.c to call out to the hooks that may or may not have been overridden inside of QEMUFileOps.

Quoted 5 lines

Hi

Quoted 52 lines
savevm.c +52 -0
+void ram_control_before_iterate(QEMUFile *f, uint64_t flags)
+{
+    int ret = 0;
+
+    if (f->ops->before_ram_iterate) {
+        ret = f->ops->before_ram_iterate(f, f->opaque, flags);
+        if (ret < 0) {
+            qemu_file_set_error(f, ret);
+        }
+    }
+}
+
+void ram_control_after_iterate(QEMUFile *f, uint64_t flags)
+{
+    int ret = 0;
+
+    if (f->ops->after_ram_iterate) {
+        ret = f->ops->after_ram_iterate(f, f->opaque, flags);
+        if (ret < 0) {
+            qemu_file_set_error(f, ret);
+        }
+    }
+}
+
+void ram_control_load_hook(QEMUFile *f, uint64_t flags)
+{
+    int ret = 0;
+
+    if (f->ops->hook_ram_load) {
+        ret = f->ops->hook_ram_load(f, f->opaque, flags);
+        if (ret < 0) {
+            qemu_file_set_error(f, ret);
+        }
+    } else {
+        qemu_file_set_error(f, ret);
+    }
+}
+
+size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,
+                         ram_addr_t offset, size_t size, int *bytes_sent)
+{
+    if (f->ops->save_page) {
+        int ret = f->ops->save_page(f, f->opaque, block_offset,
+                                    offset, size, bytes_sent);
+
+        if (ret != RAM_SAVE_CONTROL_DELAYED) {
+            if (*bytes_sent > 0) {
+                qemu_update_position(f, *bytes_sent);
+            } else if (ret < 0) {
+                qemu_file_set_error(f, ret);
+            }
+        }

savevm.c void qemu_fflush(QEMUFile *f) · line 680

Quoted 10 lines
savevm.c +7 -0
+
+        return ret;
+    }
+
+    return RAM_SAVE_CONTROL_NOT_SUPP;
+}
+
 static void qemu_fill_buffer(QEMUFile *f)
 {
     int len;

I wou0ld clame that the calls to this functions belong to this patch. Not that it makes a lot of difference though.

Later, Juan.

#20 lore raw

Re: [Qemu-devel] [PATCH v11 09/15] rdma: new QEMUFileOps hooks

Quoted 87 lines · Juan Quintela
Quoted 13 lines · [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

These are the prototypes and implementation of new hooks that RDMA takes advantage of to perform dynamic page registration.

An optional hook is also introduced for a custom function to be able to override the default save_page function.

Also included are the prototypes and accessor methods used by arch_init.c which invoke funtions inside savevm.c to call out to the hooks that may or may not have been overridden inside of QEMUFileOps.

Quoted 5 lines

Hi

Quoted 52 lines
savevm.c +52 -0
+void ram_control_before_iterate(QEMUFile *f, uint64_t flags)
+{
+    int ret = 0;
+
+    if (f->ops->before_ram_iterate) {
+        ret = f->ops->before_ram_iterate(f, f->opaque, flags);
+        if (ret < 0) {
+            qemu_file_set_error(f, ret);
+        }
+    }
+}
+
+void ram_control_after_iterate(QEMUFile *f, uint64_t flags)
+{
+    int ret = 0;
+
+    if (f->ops->after_ram_iterate) {
+        ret = f->ops->after_ram_iterate(f, f->opaque, flags);
+        if (ret < 0) {
+            qemu_file_set_error(f, ret);
+        }
+    }
+}
+
+void ram_control_load_hook(QEMUFile *f, uint64_t flags)
+{
+    int ret = 0;
+
+    if (f->ops->hook_ram_load) {
+        ret = f->ops->hook_ram_load(f, f->opaque, flags);
+        if (ret < 0) {
+            qemu_file_set_error(f, ret);
+        }
+    } else {
+        qemu_file_set_error(f, ret);
+    }
+}
+
+size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,
+                         ram_addr_t offset, size_t size, int *bytes_sent)
+{
+    if (f->ops->save_page) {
+        int ret = f->ops->save_page(f, f->opaque, block_offset,
+                                    offset, size, bytes_sent);
+
+        if (ret != RAM_SAVE_CONTROL_DELAYED) {
+            if (*bytes_sent > 0) {
+                qemu_update_position(f, *bytes_sent);
+            } else if (ret < 0) {
+                qemu_file_set_error(f, ret);
+            }
+        }

savevm.c void qemu_fflush(QEMUFile *f) · line 680

Quoted 10 lines
savevm.c +7 -0
+
+        return ret;
+    }
+
+    return RAM_SAVE_CONTROL_NOT_SUPP;
+}
+
  static void qemu_fill_buffer(QEMUFile *f)
  {
      int len;

I wou0ld clame that the calls to this functions belong to this patch. Not that it makes a lot of difference though.

Quoted 2 lines

Later, Juan.

I'll avoid rebasing if there's no strong objection - as this ordering was suggested by Paolo.

- Michael

#21 lore raw

Re: [Qemu-devel] [PATCH v11 09/15] rdma: new QEMUFileOps hooks

Il 25/06/2013 15:38, Michael R. Hines ha scritto:

Quoted 89 lines · Juan Quintela
Quoted 88 lines
Quoted 13 lines · [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

These are the prototypes and implementation of new hooks that RDMA takes advantage of to perform dynamic page registration.

An optional hook is also introduced for a custom function to be able to override the default save_page function.

Also included are the prototypes and accessor methods used by arch_init.c which invoke funtions inside savevm.c to call out to the hooks that may or may not have been overridden inside of QEMUFileOps.

Quoted 5 lines

Hi

Quoted 53 lines
savevm.c +40 -0
+void ram_control_before_iterate(QEMUFile *f, uint64_t flags)
+{
+    int ret = 0;
+
+    if (f->ops->before_ram_iterate) {
+        ret = f->ops->before_ram_iterate(f, f->opaque, flags);
+        if (ret < 0) {
+            qemu_file_set_error(f, ret);
+        }
+    }
+}
+
+void ram_control_after_iterate(QEMUFile *f, uint64_t flags)
+{
+    int ret = 0;
+
+    if (f->ops->after_ram_iterate) {
+        ret = f->ops->after_ram_iterate(f, f->opaque, flags);
+        if (ret < 0) {
+            qemu_file_set_error(f, ret);
+        }
+    }
+}
+
+void ram_control_load_hook(QEMUFile *f, uint64_t flags)
+{
+    int ret = 0;
+
+    if (f->ops->hook_ram_load) {
+        ret = f->ops->hook_ram_load(f, f->opaque, flags);
+        if (ret < 0) {
+            qemu_file_set_error(f, ret);
+        }
+    } else {
+        qemu_file_set_error(f, ret);
+    }
+}
+
+size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,
+                         ram_addr_t offset, size_t size, int

*bytes_sent)

savevm.c +12 -0
+{
+    if (f->ops->save_page) {
+        int ret = f->ops->save_page(f, f->opaque, block_offset,
+                                    offset, size, bytes_sent);
+
+        if (ret != RAM_SAVE_CONTROL_DELAYED) {
+            if (*bytes_sent > 0) {
+                qemu_update_position(f, *bytes_sent);
+            } else if (ret < 0) {
+                qemu_file_set_error(f, ret);
+            }
+        }

savevm.c void qemu_fflush(QEMUFile *f) · line 680

Quoted 10 lines
savevm.c +7 -0
+
+        return ret;
+    }
+
+    return RAM_SAVE_CONTROL_NOT_SUPP;
+}
+
  static void qemu_fill_buffer(QEMUFile *f)
  {
      int len;

I wou0ld clame that the calls to this functions belong to this patch. Not that it makes a lot of difference though.

Quoted 5 lines
Quoted 2 lines

Later, Juan.

I'll avoid rebasing if there's no strong objection - as this ordering was suggested by Paolo.

Indeed, it made my review a bit easier.

Paolo

#22 lore raw

PATCH v11 10/15 rdma: introduce capability x-rdma-pin-all

In reply to [email protected]

From: "Michael R. Hines" <[email protected]>

This capability allows you to disable dynamic chunk registration for better throughput on high-performance links.

For example, using an 8GB RAM virtual machine with all 8GB of memory in active use and the VM itself is completely idle using a 40 gbps infiniband link:

1. x-rdma-pin-all disabled total time: approximately 7.5 seconds @ 9.5 Gbps
2. x-rdma-pin-all enabled total time: approximately 4 seconds @ 26 Gbps

These numbers would of course scale up to whatever size virtual machine you have to migrate using RDMA.

Enabling this feature does *not* have any measurable affect on migration *downtime*. This is because, without this feature, all of the memory will have already been registered already in advance during the bulk round and does not need to be re-registered during the successive iteration rounds.

---
 include/migration/migration.h |    2 ++
 migration.c                   |    9 +++++++++
 qapi-schema.json              |    7 ++++++-
 3 files changed, 17 insertions(+), 1 deletion(-)
include/migration/migration.h +2 -0
index 7b153d7..9d3cc85 100644
@@ -125,6 +125,8 @@ void migrate_add_blocker(Error *reason);
  */
 void migrate_del_blocker(Error *reason);
 
+bool migrate_rdma_pin_all(void);
+
 int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen,
                          uint8_t *dst, int dlen);
 int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen);
migration.c +9 -0
index 441a3b2..a704d48 100644
@@ -476,6 +476,15 @@ void qmp_migrate_set_downtime(double value, Error **errp)
     max_downtime = (uint64_t)value;
 }
 
+bool migrate_rdma_pin_all(void)
+{
+    MigrationState *s;
+
+    s = migrate_get_current();
+
+    return s->enabled_capabilities[MIGRATION_CAPABILITY_X_RDMA_PIN_ALL];
+}
+
 int migrate_use_xbzrle(void)
 {
     MigrationState *s;
qapi-schema.json +6 -1
index 78da557..a30a728 100644
@@ -608,10 +608,15 @@
 #          This feature allows us to minimize migration traffic for certain work
 #          loads, by sending compressed difference of the pages
 #
+# @x-rdma-pin-all: Controls whether or not the entire VM memory footprint is
+#          mlock()'d on demand or all at once. Refer to docs/rdma.txt for usage.
+#          Disabled by default. Experimental: may (or may not) be renamed after
+#          further testing is complete. (since 1.6)
+#
 # Since: 1.2
 ##
 { 'enum': 'MigrationCapability',
-  'data': ['xbzrle'] }
+  'data': ['xbzrle', 'x-rdma-pin-all'] }
 
 ##
 # @MigrationCapabilityStatus
Signature · 1 line
1.7.10.4
Reviewed-by on v11 10/15
#23 lore raw

Re: [Qemu-devel] [PATCH v11 10/15] rdma: introduce capability x-rdma-pin-all

Quoted 20 lines · [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

This capability allows you to disable dynamic chunk registration for better throughput on high-performance links.

For example, using an 8GB RAM virtual machine with all 8GB of memory in active use and the VM itself is completely idle using a 40 gbps infiniband link:

1. x-rdma-pin-all disabled total time: approximately 7.5 seconds @ 9.5 Gbps
2. x-rdma-pin-all enabled total time: approximately 4 seconds @ 26 Gbps

These numbers would of course scale up to whatever size virtual machine you have to migrate using RDMA.

Enabling this feature does *not* have any measurable affect on migration *downtime*. This is because, without this feature, all of the memory will have already been registered already in advance during the bulk round and does not need to be re-registered during the successive iteration rounds.

Quoted 6 lines
#24 lore raw

PATCH v11 11/15 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                     |   29 +
 include/migration/migration.h |    4 +
 migration-rdma.c              | 2819 +++++++++++++++++++++++++++++++++++++++++
 migration.c                   |    8 +
 5 files changed, 2861 insertions(+)
 create mode 100644 migration-rdma.c
Makefile.objs +1 -0
index 5b288ba..9928542 100644
@@ -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 +29 -0
index 0e0adde..958e7b8 100755
@@ -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"
@@ -1796,6 +1803,23 @@ EOF
   libs_softmmu="$sdl_libs $libs_softmmu"
 fi
 
+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 "-Werror" "$rdma_libs" ; then
+    rdma="yes"
+    libs_softmmu="$libs_softmmu $rdma_libs"
+  else
+    if test "$rdma" = "yes" ; then
+      feature_not_found "rdma"
+    fi
+    rdma="no"
+  fi
+fi
+
 ##########################################
 # VNC TLS/WS detection
 if test "$vnc" = "yes" -a \( "$vnc_tls" != "no" -o "$vnc_ws" != "no" \) ; then
@@ -3525,6 +3549,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"
@@ -4464,6 +4489,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
index 9d3cc85..b5e413a 100644
@@ -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 +2819 -0

2,819 lines not on this page · raw message

migration.c +8 -0
index a704d48..62c6b85 100644
@@ -78,6 +78,10 @@ void qemu_start_incoming_migration(const char *uri, Error **errp)
 
     if (strstart(uri, "tcp:", &p))
         tcp_start_incoming_migration(p, errp);
+#ifdef CONFIG_RDMA
+    else if (strstart(uri, "x-rdma:", &p))
+        rdma_start_incoming_migration(p, errp);
+#endif
 #if !defined(WIN32)
     else if (strstart(uri, "exec:", &p))
         exec_start_incoming_migration(p, errp);
@@ -407,6 +411,10 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
 
     if (strstart(uri, "tcp:", &p)) {
         tcp_start_outgoing_migration(s, p, &local_err);
+#ifdef CONFIG_RDMA
+    } else if (strstart(uri, "x-rdma:", &p)) {
+        rdma_start_outgoing_migration(s, p, &local_err);
+#endif
 #if !defined(WIN32)
     } else if (strstart(uri, "exec:", &p)) {
         exec_start_outgoing_migration(s, p, &local_err);
Signature · 1 line
1.7.10.4
Reviewed-by on v11 11/15
#25 lore raw

Re: [Qemu-devel] [PATCH v11 11/15] rdma: core logic

Quoted 12 lines · [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 Makefile modifications to link this file are included.

Quoted 7 lines

Full documentation is in docs/rdma.txt

The review part is for the everything except migration-rdma.c. I am starting looking at that bits, but they are really complex and my knowledge of RDMA is nil (notice that there can be relation between the two concepts).

#26 lore raw

Re: [Qemu-devel] [PATCH v11 11/15] rdma: core logic

Quoted 20 lines · Juan Quintela
Quoted 12 lines · [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 Makefile modifications to link this file are included.

Quoted 7 lines

Full documentation is in docs/rdma.txt

Quoted 9 lines

The review part is for the everything except migration-rdma.c. I am starting looking at that bits, but they are really complex and my knowledge of RDMA is nil (notice that there can be relation between the two concepts).

Acknowledged.

#27 lore raw

Re: [Qemu-devel] [PATCH v11 11/15] rdma: core logic

In reply to [email protected]

Hi,

Quoted 2 lines · On Mon, Jun 24, 2013 at 09:58:01PM -0400, [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

[...]

Quoted 6 lines
migration-rdma.c new file +6 -0
+/*
+ * Put in the log file which RDMA device was opened and the details
+ * associated with that device.
+ */
+static void qemu_rdma_dump_id(const char *who, struct ibv_context *verbs)
+{

migration-rdma.c line 513

Quoted 10 lines
migration-rdma.c new file +10 -0
+    printf("%s RDMA Device opened: kernel name %s "
+           "uverbs device name %s, "
+           "infiniband_verbs class device path %s,"
+           " infiniband class device path %s\n",
+                who,
+                verbs->device->name,
+                verbs->device->dev_name,
+                verbs->device->dev_path,
+                verbs->device->ibdev_path);
+}

see below

Quoted 54 lines
migration-rdma.c new file +54 -0
+static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
+{
+    int ret = -EINVAL, idx;
+    struct sockaddr_in sin;
+    struct rdma_cm_id *listen_id;
+    char ip[40] = "unknown";
+
+    for (idx = 0; idx < RDMA_CONTROL_MAX_WR; idx++) {
+        rdma->wr_data[idx].control_len = 0;
+        rdma->wr_data[idx].control_curr = NULL;
+    }
+
+    if (rdma->host == NULL) {
+        ERROR(errp, "RDMA host is not set!\n");
+        rdma->error_state = -EINVAL;
+        return -1;
+    }
+    /* create CM channel */
+    rdma->channel = rdma_create_event_channel();
+    if (!rdma->channel) {
+        ERROR(errp, "could not create rdma event channel\n");
+        rdma->error_state = -EINVAL;
+        return -1;
+    }
+
+    /* create CM id */
+    ret = rdma_create_id(rdma->channel, &listen_id, NULL, RDMA_PS_TCP);
+    if (ret) {
+        ERROR(errp, "could not create cm_id!\n");
+        goto err_dest_init_create_listen_id;
+    }
+
+    memset(&sin, 0, sizeof(sin));
+    sin.sin_family = AF_INET;
+    sin.sin_port = htons(rdma->port);
+
+    if (rdma->host && strcmp("", rdma->host)) {
+        struct hostent *dest_addr;
+        dest_addr = gethostbyname(rdma->host);
+        if (!dest_addr) {
+            ERROR(errp, "migration could not gethostbyname!\n");
+            ret = -EINVAL;
+            goto err_dest_init_bind_addr;
+        }
+        memcpy(&sin.sin_addr.s_addr, dest_addr->h_addr,
+                dest_addr->h_length);
+        inet_ntop(AF_INET, dest_addr->h_addr, ip, sizeof ip);
+    } else {
+        sin.sin_addr.s_addr = INADDR_ANY;
+    }
+
+    DPRINTF("%s => %s\n", rdma->host, ip);
+
+    ret = rdma_bind_addr(listen_id, (struct sockaddr *)&sin);

migration-rdma.c line 2012

Quoted 10 lines
migration-rdma.c new file +10 -0
+    if (ret) {
+        ERROR(errp, "Error: could not rdma_bind_addr!\n");
+        goto err_dest_init_bind_addr;
+    }
+
+    rdma->listen_id = listen_id;
+    if (listen_id->verbs) {
+        rdma->verbs = listen_id->verbs;
+    }
+    qemu_rdma_dump_id("dest_init", rdma->verbs);

I wonder if you have ever hit the case where rdma_bind_addr() does not set the verbs structure in listen_id because we are binding to the loopback device (also see linux kernel commit 8523c048).
I keep hitting this case on my destination VM ("incoming x-rdma:host:port)

Then I think qemu_rdma_dump_id can segfault trying to dereference a null verbs structure. The dump_id function should check for non-NULL verbs argument, or the dump should be made only in the (verbs != NULL) if clause.

Disabling the dump_id above, I have rdma_resolve_addr() problems on the source VM side (getting RDMA_CM_EVENT_ADDR_ERROR instead of RDMA_CM_EVENT_ADDR_RESOLVED).

I assume that is because of the null verbs structure destination problem above. qemu_rdma_dest_prepare() will always fail with a NULL verbs argument:

migration-rdma.c line 2034

Quoted 10 lines
migration-rdma.c new file +10 -0
+
+static int qemu_rdma_dest_prepare(RDMAContext *rdma, Error **errp)
+{
+    int ret;
+    int idx;
+
+    if (!rdma->verbs) {
+        ERROR(errp, "no verbs context!\n");
+        return 0;
+    }

It is first called from rdma_start_incoming_migration() and will fail with the loopback binding case (rdma->verbs == NULL).

however later qemu_rdma_accept() will check against the incoming cm_event verbs structure and set the RDMAContext's verb struct, calling qemu_rdma_dest_prepare with that struct:

[...]

Quoted 1 line

+static int qemu_rdma_accept(RDMAContext *rdma)

[...]

migration-rdma.c line 2365

Quoted 11 lines
migration-rdma.c new file +11 -0
+    if (!rdma->verbs) {
+        rdma->verbs = verbs;
+        /*
+         * Cannot propagate errp, as there is no error pointer
+         * to be propagated.
+         */
+        ret = qemu_rdma_dest_prepare(rdma, NULL);
+        if (ret) {
+            fprintf(stderr, "rdma migration: error preparing dest!\n");
+            goto err_rdma_dest_wait;
+        }

Are these two cases intentionally different?

thanks,

- Vasilis

#28 lore raw

Re: [Qemu-devel] [PATCH v11 11/15] rdma: core logic

Il 25/06/2013 18:31, Vasilis Liaskovitis ha scritto:

Quoted 10 lines

Then I think qemu_rdma_dump_id can segfault trying to dereference a null verbs structure. The dump_id function should check for non-NULL verbs argument, or the dump should be made only in the (verbs != NULL) if clause.

Disabling the dump_id above, I have rdma_resolve_addr() problems on the source VM side (getting RDMA_CM_EVENT_ADDR_ERROR instead of RDMA_CM_EVENT_ADDR_RESOLVED).

I assume that is because of the null verbs structure destination problem above. qemu_rdma_dest_prepare() will always fail with a NULL verbs argument:

FWIW, I don't think this should block merging this patch. We will always find one more bug after merging 2500 lines of code.

Paolo

#29 lore raw

Re: [Qemu-devel] [PATCH v11 11/15] rdma: core logic

In reply to Vasilis Liaskovitis
Quoted 98 lines · Vasilis Liaskovitis

Hi,

Quoted 2 lines · On Mon, Jun 24, 2013 at 09:58:01PM -0400, [email protected] wrote:

From: "Michael R. Hines" <[email protected]>

[...]

Quoted 6 lines
migration-rdma.c new file +6 -0
+/*
+ * Put in the log file which RDMA device was opened and the details
+ * associated with that device.
+ */
+static void qemu_rdma_dump_id(const char *who, struct ibv_context *verbs)
+{

migration-rdma.c line 513

Quoted 10 lines
migration-rdma.c new file +10 -0
+    printf("%s RDMA Device opened: kernel name %s "
+           "uverbs device name %s, "
+           "infiniband_verbs class device path %s,"
+           " infiniband class device path %s\n",
+                who,
+                verbs->device->name,
+                verbs->device->dev_name,
+                verbs->device->dev_path,
+                verbs->device->ibdev_path);
+}

see below

Quoted 54 lines
migration-rdma.c new file +54 -0
+static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
+{
+    int ret = -EINVAL, idx;
+    struct sockaddr_in sin;
+    struct rdma_cm_id *listen_id;
+    char ip[40] = "unknown";
+
+    for (idx = 0; idx < RDMA_CONTROL_MAX_WR; idx++) {
+        rdma->wr_data[idx].control_len = 0;
+        rdma->wr_data[idx].control_curr = NULL;
+    }
+
+    if (rdma->host == NULL) {
+        ERROR(errp, "RDMA host is not set!\n");
+        rdma->error_state = -EINVAL;
+        return -1;
+    }
+    /* create CM channel */
+    rdma->channel = rdma_create_event_channel();
+    if (!rdma->channel) {
+        ERROR(errp, "could not create rdma event channel\n");
+        rdma->error_state = -EINVAL;
+        return -1;
+    }
+
+    /* create CM id */
+    ret = rdma_create_id(rdma->channel, &listen_id, NULL, RDMA_PS_TCP);
+    if (ret) {
+        ERROR(errp, "could not create cm_id!\n");
+        goto err_dest_init_create_listen_id;
+    }
+
+    memset(&sin, 0, sizeof(sin));
+    sin.sin_family = AF_INET;
+    sin.sin_port = htons(rdma->port);
+
+    if (rdma->host && strcmp("", rdma->host)) {
+        struct hostent *dest_addr;
+        dest_addr = gethostbyname(rdma->host);
+        if (!dest_addr) {
+            ERROR(errp, "migration could not gethostbyname!\n");
+            ret = -EINVAL;
+            goto err_dest_init_bind_addr;
+        }
+        memcpy(&sin.sin_addr.s_addr, dest_addr->h_addr,
+                dest_addr->h_length);
+        inet_ntop(AF_INET, dest_addr->h_addr, ip, sizeof ip);
+    } else {
+        sin.sin_addr.s_addr = INADDR_ANY;
+    }
+
+    DPRINTF("%s => %s\n", rdma->host, ip);
+
+    ret = rdma_bind_addr(listen_id, (struct sockaddr *)&sin);

migration-rdma.c line 2012

Quoted 10 lines
migration-rdma.c new file +10 -0
+    if (ret) {
+        ERROR(errp, "Error: could not rdma_bind_addr!\n");
+        goto err_dest_init_bind_addr;
+    }
+
+    rdma->listen_id = listen_id;
+    if (listen_id->verbs) {
+        rdma->verbs = listen_id->verbs;
+    }
+    qemu_rdma_dump_id("dest_init", rdma->verbs);

I wonder if you have ever hit the case where rdma_bind_addr() does not set the verbs structure in listen_id because we are binding to the loopback device (also see linux kernel commit 8523c048).
I keep hitting this case on my destination VM ("incoming x-rdma:host:port)

Then I think qemu_rdma_dump_id can segfault trying to dereference a null verbs structure. The dump_id function should check for non-NULL verbs argument, or the dump should be made only in the (verbs != NULL) if clause.

Quoted 6 lines

Disabling the dump_id above, I have rdma_resolve_addr() problems on the source VM side (getting RDMA_CM_EVENT_ADDR_ERROR instead of RDMA_CM_EVENT_ADDR_RESOLVED).

I assume that is because of the null verbs structure destination problem above. qemu_rdma_dest_prepare() will always fail with a NULL verbs argument:

Good catch, thank you. I'll fix this immediately in the next version.

I never tried binding to the localhost before......

Quoted 31 lines

migration-rdma.c line 2034

Quoted 10 lines
migration-rdma.c new file +10 -0
+
+static int qemu_rdma_dest_prepare(RDMAContext *rdma, Error **errp)
+{
+    int ret;
+    int idx;
+
+    if (!rdma->verbs) {
+        ERROR(errp, "no verbs context!\n");
+        return 0;
+    }

It is first called from rdma_start_incoming_migration() and will fail with the loopback binding case (rdma->verbs == NULL).

however later qemu_rdma_accept() will check against the incoming cm_event verbs structure and set the RDMAContext's verb struct, calling qemu_rdma_dest_prepare with that struct:

[...]

Quoted 1 line

+static int qemu_rdma_accept(RDMAContext *rdma)

[...]

migration-rdma.c line 2365

Quoted 11 lines
migration-rdma.c new file +11 -0
+    if (!rdma->verbs) {
+        rdma->verbs = verbs;
+        /*
+         * Cannot propagate errp, as there is no error pointer
+         * to be propagated.
+         */
+        ret = qemu_rdma_dest_prepare(rdma, NULL);
+        if (ret) {
+            fprintf(stderr, "rdma migration: error preparing dest!\n");
+            goto err_rdma_dest_wait;
+        }
Quoted 1 line

Are these two cases intentionally different?

Another good catch. We should definitely allow loopback RDMA without any issues.

I will fix this immediately as well in the next version.

- Michael

#30 lore raw

PATCH v11 12/15 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
index 00bc3a9..5ea32db 100644
@@ -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++;
                 if (!ram_bulk_stage) {
                     bytes_sent = save_block_hdr(f, block, offset, cont,
@@ -610,6 +623,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;
@@ -628,6 +645,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) {
@@ -658,6 +677,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;
@@ -675,6 +700,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 */
@@ -688,6 +715,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();
@@ -884,6 +913,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
#31 lore raw

PATCH v11 13/15 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
index 62c6b85..dcb99c9 100644
@@ -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 (__sync_val_compare_and_swap(&s->state, MIG_STATE_ACTIVE,
+    if (__sync_val_compare_and_swap(&s->state, old_state,
                                     new_state) == new_state) {
         trace_migrate_set_state(new_state);
     }
@@ -316,7 +316,7 @@ static void migrate_fd_cancel(MigrationState *s)
 {
     DPRINTF("cancelling migration\n");
 
-    migrate_finish_set_state(s, MIG_STATE_CANCELLED);
+    migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_CANCELLED);
 }
 
 void add_migration_state_change_notifier(Notifier *notify)
@@ -546,14 +546,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
Reviewed-by on v11 13/15
#32 lore raw

Re: [Qemu-devel] [PATCH v11 13/15] rdma: allow state transitions between other states besides ACTIVE

Quoted 14 lines · [email protected] wrote:

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.

Quoted 8 lines

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.

#33 lore raw

PATCH v11 14/15 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 |   22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
migration.c +15 -7
index dcb99c9..758d99d 100644
@@ -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;
     }
@@ -316,6 +321,7 @@ static void migrate_fd_cancel(MigrationState *s)
 {
     DPRINTF("cancelling migration\n");
 
+    migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_CANCELLED);
     migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_CANCELLED);
 }
 
@@ -393,7 +399,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;
     }
@@ -525,6 +531,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;
@@ -604,8 +612,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
#34 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Quoted 26 lines · [email protected] wrote:

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 static void migrate_fd_cancel(MigrationState *s) · line 326

Quoted 6 lines
migration.c +1 -0
@@ -316,6 +321,7 @@ static void migrate_fd_cancel(MigrationState *s)
 {
     DPRINTF("cancelling migration\n");
 
+    migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_CANCELLED);
     migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_CANCELLED);
 }

This chunk is wrong.

we can call qme_migrate_cancel() at any point, and it is going to be called normally from MIG_STATE_ACTIVE.

    migrate_set_satet(s, s->state,  MIG_STATE_CANCELLED)

should do the trick. Or something like that, what do you think?

Later, Juan.

#35 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Il 25/06/2013 11:49, Juan Quintela ha scritto:

Quoted 36 lines
Quoted 26 lines · [email protected] wrote:

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 static void migrate_fd_cancel(MigrationState *s) · line 326

Quoted 6 lines
migration.c +1 -0
@@ -316,6 +321,7 @@ static void migrate_fd_cancel(MigrationState *s)
 {
     DPRINTF("cancelling migration\n");
 
+    migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_CANCELLED);
     migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_CANCELLED);
 }

This chunk is wrong.

Quoted 6 lines

we can call qme_migrate_cancel() at any point, and it is going to be called normally from MIG_STATE_ACTIVE.

    migrate_set_satet(s, s->state,  MIG_STATE_CANCELLED)

should do the trick. Or something like that, what do you think?

I don't like the three-arguments migrate_set_state, but I don't have any better idea.

With Juan's modification, it is fine (but not reviewed-by me :)). While you resend, the first 13 patches of v10 can be merged (pull request). You can then rebase the last three on top.

Michael, did you look at the "debugging/getting the protocol ready" mode where all pages are unpinned?

Paolo

#36 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Quoted 40 lines · Paolo Bonzini

Il 25/06/2013 11:49, Juan Quintela ha scritto:

Quoted 39 lines
Quoted 25 lines · [email protected] wrote:

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 static void migrate_fd_cancel(MigrationState *s) · line 326

Quoted 6 lines
migration.c +1 -0
@@ -316,6 +321,7 @@ static void migrate_fd_cancel(MigrationState *s)
  {
      DPRINTF("cancelling migration\n");
 
+    migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_CANCELLED);
      migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_CANCELLED);
  }

This chunk is wrong.

we can call qme_migrate_cancel() at any point, and it is going to be called normally from MIG_STATE_ACTIVE.

     migrate_set_satet(s, s->state,  MIG_STATE_CANCELLED)
Quoted 7 lines
Quoted 1 line

should do the trick. Or something like that, what do you think?

I don't like the three-arguments migrate_set_state, but I don't have any better idea.

With Juan's modification, it is fine (but not reviewed-by me :)). While you resend, the first 13 patches of v10 can be merged (pull request). You can then rebase the last three on top.

So, I should send a v11 before Juan applies and generates the pull request?

Did I understand correctly?

Quoted 5 lines

Michael, did you look at the "debugging/getting the protocol ready" mode where all pages are unpinned?

Paolo

We did not come up with a design on how such a mode would be exposed to the user. Implementing this in migration-rdma.c is just a few lines of code, but without a clear use case in this patch series, I've not chosen expose it to the user yet without some kind of agreement with you guys.

Recommendations?

#37 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Il 25/06/2013 15:44, Michael R. Hines ha scritto:

Quoted 11 lines
Quoted 7 lines
Quoted 1 line

I don't like the three-arguments migrate_set_state, but I don't have any better idea.

With Juan's modification, it is fine (but not reviewed-by me :)). While you resend, the first 13 patches of v10 can be merged (pull request). You can then rebase the last three on top.

So, I should send a v11 before Juan applies and generates the pull request?

Did I understand correctly?

Juan found another small nit, so please do send a v12. He liked (with the small change in cancellation) your last three patches, so there is no need to split out patch 13 (as you had it in v10).

Quoted 8 lines
Quoted 2 lines

Michael, did you look at the "debugging/getting the protocol ready" mode where all pages are unpinned?

We did not come up with a design on how such a mode would be exposed to the user. Implementing this in migration-rdma.c is just a few lines of code, but without a clear use case in this patch series, I've not chosen expose it to the user yet without some kind of agreement with you guys.

Do those few lines of code change the protocol? If yes, I'll go against all my previous recommendations and suggest a #define. If no, it is fine to leave it for later, but I would still suggest posting the patch on the list just for information.

Paolo

#38 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Quoted 7 lines · Paolo Bonzini

Il 25/06/2013 15:44, Michael R. Hines ha scritto:

Quoted 6 lines
Quoted 6 lines

I don't like the three-arguments migrate_set_state, but I don't have any better idea.

With Juan's modification, it is fine (but not reviewed-by me :)). While you resend, the first 13 patches of v10 can be merged (pull request). You can then rebase the last three on top.

Quoted 6 lines
Quoted 3 lines

So, I should send a v11 before Juan applies and generates the pull request?

Did I understand correctly?

Juan found another small nit, so please do send a v12. He liked (with the small change in cancellation) your last three patches, so there is no need to split out patch 13 (as you had it in v10).

Acknowledged.

Quoted 7 lines
Quoted 7 lines
Quoted 2 lines

Michael, did you look at the "debugging/getting the protocol ready" mode where all pages are unpinned?

We did not come up with a design on how such a mode would be exposed to the user. Implementing this in migration-rdma.c is just a few lines of code, but without a clear use case in this patch series, I've not chosen expose it to the user yet without some kind of agreement with you guys.

Quoted 7 lines

Do those few lines of code change the protocol? If yes, I'll go against all my previous recommendations and suggest a #define. If no, it is fine to leave it for later, but I would still suggest posting the patch on the list just for information.

Paolo

Ok, you got it - no it does not change the protocol. I'll use a #define and send it out with a new version for review.

- Michael

#39 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Il 25/06/2013 16:54, Michael R. Hines ha scritto:

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Do those few lines of code change the protocol? If yes, I'll go against all my previous recommendations and suggest a #define. If no, it is fine to leave it for later, but I would still suggest posting the patch on the list just for information.

Ok, you got it - no it does not change the protocol. I'll use a #define and send it out with a new version for review.

Make sure you send an additional patch on top of these 15.

Paolo

#40 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Quoted 11 lines · Paolo Bonzini

Il 25/06/2013 16:54, Michael R. Hines ha scritto:

Quoted 6 lines
Quoted 4 lines

Do those few lines of code change the protocol? If yes, I'll go against all my previous recommendations and suggest a #define. If no, it is fine to leave it for later, but I would still suggest posting the patch on the list just for information.

Ok, you got it - no it does not change the protocol. I'll use a #define and send it out with a new version for review.

Make sure you send an additional patch on top of these 15.

Paolo

Understood.

- Michael

#41 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

In reply to Paolo Bonzini
Quoted 11 lines · Paolo Bonzini

Il 25/06/2013 16:54, Michael R. Hines ha scritto:

Quoted 6 lines
Quoted 4 lines

Do those few lines of code change the protocol? If yes, I'll go against all my previous recommendations and suggest a #define. If no, it is fine to leave it for later, but I would still suggest posting the patch on the list just for information.

Ok, you got it - no it does not change the protocol. I'll use a #define and send it out with a new version for review.

Make sure you send an additional patch on top of these 15.

Paolo

I was wrong - this does require a protocol extension.

This is because the RDMA transfers are asynchronous, and thus we cannot know in advance that it is safe to unregister the memory associated with each individual transfer before the transfer actually completes.

While the destination currently uses the protocol to participate in *registering* the page, the destination does not participate in the RDMA transfers themselves, only the source does, and thus would require a new exchange of messages to block and instruct the destination to unpin the memory.

- Michael

#42 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Il 25/06/2013 22:56, Michael R. Hines ha scritto:

Quoted 8 lines
Quoted 1 line

I was wrong - this does require a protocol extension.

This is because the RDMA transfers are asynchronous, and thus we cannot know in advance that it is safe to unregister the memory associated with each individual transfer before the transfer actually completes.

Quoted 5 lines

While the destination currently uses the protocol to participate in *registering* the page, the destination does not participate in the RDMA transfers themselves, only the source does, and thus would require a new exchange of messages to block and instruct the destination to unpin the memory.

Yes, that's what I recalled too (really what mst told me :)). Does it need to be blocking though? As long as the pinning is blocking, and messages are processed in order, the source can proceed immediately after sending an unpin message. This assumes of course that the chunk is not being transmitted, and I am not sure how easy the source can determine that.

Paolo

#43 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Quoted 13 lines · Paolo Bonzini

Il 25/06/2013 22:56, Michael R. Hines ha scritto:

Quoted 7 lines

I was wrong - this does require a protocol extension.

This is because the RDMA transfers are asynchronous, and thus we cannot know in advance that it is safe to unregister the memory associated with each individual transfer before the transfer actually completes.

Quoted 5 lines

While the destination currently uses the protocol to participate in *registering* the page, the destination does not participate in the RDMA transfers themselves, only the source does, and thus would require a new exchange of messages to block and instruct the destination to unpin the memory.

Quoted 9 lines

Yes, that's what I recalled too (really what mst told me :)). Does it need to be blocking though? As long as the pinning is blocking, and messages are processed in order, the source can proceed immediately after sending an unpin message. This assumes of course that the chunk is not being transmitted, and I am not sure how easy the source can determine that.

Paolo

No, they're not processed in order. In fact, not only does the device write out of order, but also the PCI bus writes out of order. This was such a problem in fact, that I fixed several bugs as a result a few weeks ago (v7 of the patch with an in-depth description).

The destination simply cannot assume whatsoever what the ordering of the writes are - that's really the whole point of using RDMA in the first place so that the software can get out of the way of the transfer process to lower the latency of each transfer.

The only option is to send a blocking message to the other side to request the unpinning (in addition to unpinning on the source first upon completion of the original transfer).

As you can expect, this would be very expensive and we must ensure that we have *very* good a-priori information that this memory will not need to be re-registered anytime in the near future.

- Michael

#44 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Il 26/06/2013 02:31, Michael R. Hines ha scritto:

Quoted 26 lines · Paolo Bonzini
Quoted 13 lines

Il 25/06/2013 22:56, Michael R. Hines ha scritto:

Quoted 7 lines

I was wrong - this does require a protocol extension.

This is because the RDMA transfers are asynchronous, and thus we cannot know in advance that it is safe to unregister the memory associated with each individual transfer before the transfer actually completes.

Quoted 5 lines

While the destination currently uses the protocol to participate in *registering* the page, the destination does not participate in the RDMA transfers themselves, only the source does, and thus would require a new exchange of messages to block and instruct the destination to unpin the memory.

Quoted 6 lines

Yes, that's what I recalled too (really what mst told me :)). Does it need to be blocking though? As long as the pinning is blocking, and messages are processed in order, the source can proceed immediately after sending an unpin message. This assumes of course that the chunk is not being transmitted, and I am not sure how easy the source can determine that.

No, they're not processed in order. In fact, not only does the device write out of order, but also the PCI bus writes out of order. This was such a problem in fact, that I fixed several bugs as a result a few weeks ago (v7 of the patch with an in-depth description).

Quoted 4 lines

The destination simply cannot assume whatsoever what the ordering of the writes are - that's really the whole point of using RDMA in the first place so that the software can get out of the way of the transfer process to lower the latency of each transfer.

The memory is processed out of order, but what about the messages? Those must be in order.

Note that I wrote above "This assumes of course that the chunk is not being transmitted". Can the source know when an asynchronous transfer finished, and delay the unpinning until that time?

Paolo

Quoted 13 lines

The only option is to send a blocking message to the other side to request the unpinning (in addition to unpinning on the source first upon completion of the original transfer).

As you can expect, this would be very expensive and we must ensure that we have *very* good a-priori information that this memory will not need to be re-registered anytime in the near future.

- Michael

#45 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Quoted 30 lines · Paolo Bonzini

Il 26/06/2013 02:31, Michael R. Hines ha scritto:

Quoted 25 lines · Paolo Bonzini
Quoted 13 lines

Il 25/06/2013 22:56, Michael R. Hines ha scritto:

Quoted 7 lines

I was wrong - this does require a protocol extension.

This is because the RDMA transfers are asynchronous, and thus we cannot know in advance that it is safe to unregister the memory associated with each individual transfer before the transfer actually completes.

Quoted 5 lines

While the destination currently uses the protocol to participate in *registering* the page, the destination does not participate in the RDMA transfers themselves, only the source does, and thus would require a new exchange of messages to block and instruct the destination to unpin the memory.

Quoted 6 lines

Yes, that's what I recalled too (really what mst told me :)). Does it need to be blocking though? As long as the pinning is blocking, and messages are processed in order, the source can proceed immediately after sending an unpin message. This assumes of course that the chunk is not being transmitted, and I am not sure how easy the source can determine that.

No, they're not processed in order. In fact, not only does the device write out of order, but also the PCI bus writes out of order. This was such a problem in fact, that I fixed several bugs as a result a few weeks ago (v7 of the patch with an in-depth description).

Quoted 4 lines

The destination simply cannot assume whatsoever what the ordering of the writes are - that's really the whole point of using RDMA in the first place so that the software can get out of the way of the transfer process to lower the latency of each transfer.

Quoted 8 lines

The memory is processed out of order, but what about the messages? Those must be in order.

Note that I wrote above "This assumes of course that the chunk is not being transmitted". Can the source know when an asynchronous transfer finished, and delay the unpinning until that time?

Paolo

Yes, the source does know. There's no problem unpinning on the source.

But both sides must do the unpinning, not just the source.

Did I misunderstand you? Are you suggesting *only* unpinning on the source?

- Michael

#46 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Il 26/06/2013 14:37, Michael R. Hines ha scritto:

Quoted 38 lines · Paolo Bonzini
Quoted 30 lines

Il 26/06/2013 02:31, Michael R. Hines ha scritto:

Quoted 25 lines · Paolo Bonzini
Quoted 13 lines

Il 25/06/2013 22:56, Michael R. Hines ha scritto:

Quoted 7 lines

I was wrong - this does require a protocol extension.

This is because the RDMA transfers are asynchronous, and thus we cannot know in advance that it is safe to unregister the memory associated with each individual transfer before the transfer actually completes.

Quoted 5 lines

While the destination currently uses the protocol to participate in *registering* the page, the destination does not participate in the RDMA transfers themselves, only the source does, and thus would require a new exchange of messages to block and instruct the destination to unpin the memory.

Quoted 6 lines

Yes, that's what I recalled too (really what mst told me :)). Does it need to be blocking though? As long as the pinning is blocking, and messages are processed in order, the source can proceed immediately after sending an unpin message. This assumes of course that the chunk is not being transmitted, and I am not sure how easy the source can determine that.

No, they're not processed in order. In fact, not only does the device write out of order, but also the PCI bus writes out of order. This was such a problem in fact, that I fixed several bugs as a result a few weeks ago (v7 of the patch with an in-depth description).

Quoted 4 lines

The destination simply cannot assume whatsoever what the ordering of the writes are - that's really the whole point of using RDMA in the first place so that the software can get out of the way of the transfer process to lower the latency of each transfer.

Quoted 6 lines

The memory is processed out of order, but what about the messages? Those must be in order.

Note that I wrote above "This assumes of course that the chunk is not being transmitted". Can the source know when an asynchronous transfer finished, and delay the unpinning until that time?

Quoted 5 lines

Yes, the source does know. There's no problem unpinning on the source.

But both sides must do the unpinning, not just the source.

Did I misunderstand you? Are you suggesting *only* unpinning on the source?

I'm suggesting (if possible) that the source only tells the destination to unpin once it knows it is safe for the destination to do it. As long as unpin and pin messages are not reordered, it should be possible to do it with an asynchronous message from the source to the destination.

Paolo

#47 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Quoted 42 lines · Paolo Bonzini

Il 26/06/2013 14:37, Michael R. Hines ha scritto:

Quoted 41 lines · Paolo Bonzini
Quoted 30 lines

Il 26/06/2013 02:31, Michael R. Hines ha scritto:

Quoted 25 lines · Paolo Bonzini
Quoted 13 lines

Il 25/06/2013 22:56, Michael R. Hines ha scritto:

Quoted 7 lines

I was wrong - this does require a protocol extension.

This is because the RDMA transfers are asynchronous, and thus we cannot know in advance that it is safe to unregister the memory associated with each individual transfer before the transfer actually completes.

Quoted 5 lines

While the destination currently uses the protocol to participate in *registering* the page, the destination does not participate in the RDMA transfers themselves, only the source does, and thus would require a new exchange of messages to block and instruct the destination to unpin the memory.

Quoted 6 lines

Yes, that's what I recalled too (really what mst told me :)). Does it need to be blocking though? As long as the pinning is blocking, and messages are processed in order, the source can proceed immediately after sending an unpin message. This assumes of course that the chunk is not being transmitted, and I am not sure how easy the source can determine that.

No, they're not processed in order. In fact, not only does the device write out of order, but also the PCI bus writes out of order. This was such a problem in fact, that I fixed several bugs as a result a few weeks ago (v7 of the patch with an in-depth description).

Quoted 4 lines

The destination simply cannot assume whatsoever what the ordering of the writes are - that's really the whole point of using RDMA in the first place so that the software can get out of the way of the transfer process to lower the latency of each transfer.

Quoted 6 lines

The memory is processed out of order, but what about the messages? Those must be in order.

Note that I wrote above "This assumes of course that the chunk is not being transmitted". Can the source know when an asynchronous transfer finished, and delay the unpinning until that time?

Yes, the source does know. There's no problem unpinning on the source.

But both sides must do the unpinning, not just the source.

Quoted 8 lines
Quoted 1 line

Did I misunderstand you? Are you suggesting *only* unpinning on the source?

I'm suggesting (if possible) that the source only tells the destination to unpin once it knows it is safe for the destination to do it. As long as unpin and pin messages are not reordered, it should be possible to do it with an asynchronous message from the source to the destination.

Paolo

Oh, certainly. I agree. That's not a trivial patch, though (as we were originally shooting for).

(I'll list the steps below on the QEMU wiki, for the record).

*This requires some steps:*
1. First, maintain a new data structure: something like
"These memory ranges are 'being unpinned'" - block all potential writes to these addresses until the unpinning completes.
2. Once the source unpin completes, send the asynchronous control channel message to the other side for unpinning.
2. Mark the data structure and return and allow the migration to continue with the next RDMA write.
3. Upon completion of the unpinning on the destination,
respond to the source that it was finished.
4. Source then clears the data structure for the successfully unpinned memory ranges.
5. At this point, one or more writes may (or may not) be blocking on the unpinned memory areas and will poll the data structure and find that the unpinning has completed.
6. Then issue the new writes and proceed as normal.
7. Repeat step 1.

#48 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Il 26/06/2013 16:09, Michael R. Hines ha scritto:

Quoted 10 lines

*This requires some steps:*
1. First, maintain a new data structure: something like
"These memory ranges are 'being unpinned'" - block all potential writes to these addresses until the unpinning completes.
2. Once the source unpin completes, send the asynchronous control channel message
to the other side for unpinning.
2. Mark the data structure and return and allow the migration to continue with the next RDMA write.
3. Upon completion of the unpinning on the destination,

Quoted 8 lines

respond to the source that it was finished.
4. Source then clears the data structure for the successfully unpinned memory ranges.
5. At this point, one or more writes may (or may not) be blocking on the unpinned memory areas and will poll the data structure and find that the unpinning has completed.
6. Then issue the new writes and proceed as normal.
7. Repeat step 1.

After more discussion on IRC I think I understand this. It's not trivial, but not super-complex either... it would really be nice to add it to the protocol already in 1.6.

Paolo

#49 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Quoted 19 lines · Paolo Bonzini

Il 26/06/2013 16:09, Michael R. Hines ha scritto:

Quoted 10 lines

*This requires some steps:*
1. First, maintain a new data structure: something like
"These memory ranges are 'being unpinned'" - block all potential writes to these addresses until the unpinning completes.
2. Once the source unpin completes, send the asynchronous control channel message
to the other side for unpinning.
2. Mark the data structure and return and allow the migration to continue with the next RDMA write.
3. Upon completion of the unpinning on the destination,

Quoted 8 lines

respond to the source that it was finished.
4. Source then clears the data structure for the successfully unpinned memory ranges.
5. At this point, one or more writes may (or may not) be blocking on the unpinned memory areas and will poll the data structure and find that the unpinning has completed.
6. Then issue the new writes and proceed as normal.
7. Repeat step 1.

Quoted 6 lines

After more discussion on IRC I think I understand this. It's not trivial, but not super-complex either... it would really be nice to add it to the protocol already in 1.6.

Paolo

I will submit this as a brand new patch series. I'm working on it right now.

- Michael

#50 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

In reply to Michael R. Hines
Quoted 59 lines · Michael R. Hines
Quoted 39 lines · Paolo Bonzini

Il 25/06/2013 11:49, Juan Quintela ha scritto:

Quoted 38 lines
Quoted 25 lines · [email protected] wrote:

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 static void migrate_fd_cancel(MigrationState *s) · line 325

Quoted 5 lines
migration.c +0 -0
@@ -316,6 +321,7 @@ static void migrate_fd_cancel(MigrationState *s)
  {
      DPRINTF("cancelling migration\n");
  +    migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_CANCELLED);
      migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_CANCELLED);
  }

This chunk is wrong.

we can call qme_migrate_cancel() at any point, and it is going to be called normally from MIG_STATE_ACTIVE.

     migrate_set_satet(s, s->state,  MIG_STATE_CANCELLED)
Quoted 7 lines
Quoted 1 line

should do the trick. Or something like that, what do you think?

I don't like the three-arguments migrate_set_state, but I don't have any better idea.

With Juan's modification, it is fine (but not reviewed-by me :)). While you resend, the first 13 patches of v10 can be merged (pull request). You can then rebase the last three on top.

So, I should send a v11 before Juan applies and generates the pull request?

Did I understand correctly?

Quoted 5 lines

Michael, did you look at the "debugging/getting the protocol ready" mode where all pages are unpinned?

Paolo

Quoted 7 lines

We did not come up with a design on how such a mode would be exposed to the user. Implementing this in migration-rdma.c is just a few lines of code, but without a clear use case in this patch series, I've not chosen expose it to the user yet without some kind of agreement with you guys.

Recommendations?

Dunno. I have tried to use the thing:

I am using -incoming x-rdma:deus:4444

(qemu) char device redirected to /dev/pts/2 (label serial0)
librdmacm: Warning: couldn't read ABI version.
librdmacm: Warning: assuming: 4
librdmacm: Fatal: unable to get RDMA device list
RDMA ERROR: could not create rdma event channel
-incoming x-rdma:deus:4444: RDMA ERROR: could not create rdma event channel

I also used "0" instead of deus (the machine name).

The only thing that I did appart from intsalling librdmacm-devel was:

# cat /etc/udev/rules.d/80-infinibad.rules
KERNEL="rdma_cm", NAME="infiniband/%k", MODE="0666"

As per README. Something else I need to do to use the tcp implementations?

Later, Juan.

#51 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

Quoted 67 lines · Juan Quintela
Quoted 57 lines · Michael R. Hines
Quoted 39 lines · Paolo Bonzini

Il 25/06/2013 11:49, Juan Quintela ha scritto:

Quoted 38 lines
Quoted 25 lines · [email protected] wrote:

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 static void migrate_fd_cancel(MigrationState *s) · line 325

Quoted 5 lines
migration.c +0 -0
@@ -316,6 +321,7 @@ static void migrate_fd_cancel(MigrationState *s)
   {
       DPRINTF("cancelling migration\n");
   +    migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_CANCELLED);
       migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_CANCELLED);
   }

This chunk is wrong.

we can call qme_migrate_cancel() at any point, and it is going to be called normally from MIG_STATE_ACTIVE.

      migrate_set_satet(s, s->state,  MIG_STATE_CANCELLED)
Quoted 7 lines
Quoted 1 line

should do the trick. Or something like that, what do you think?

I don't like the three-arguments migrate_set_state, but I don't have any better idea.

With Juan's modification, it is fine (but not reviewed-by me :)). While you resend, the first 13 patches of v10 can be merged (pull request). You can then rebase the last three on top.

So, I should send a v11 before Juan applies and generates the pull request?

Did I understand correctly?

Quoted 5 lines

Michael, did you look at the "debugging/getting the protocol ready" mode where all pages are unpinned?

Paolo

Quoted 7 lines

We did not come up with a design on how such a mode would be exposed to the user. Implementing this in migration-rdma.c is just a few lines of code, but without a clear use case in this patch series, I've not chosen expose it to the user yet without some kind of agreement with you guys.

Recommendations?

Dunno. I have tried to use the thing:

Quoted 9 lines

I am using -incoming x-rdma:deus:4444

(qemu) char device redirected to /dev/pts/2 (label serial0)
librdmacm: Warning: couldn't read ABI version.
librdmacm: Warning: assuming: 4
librdmacm: Fatal: unable to get RDMA device list
RDMA ERROR: could not create rdma event channel
-incoming x-rdma:deus:4444: RDMA ERROR: could not create rdma event channel

This means that your RDMA environment / IB configuration (outside of QEMU) is not configured properly. There are several "sanity checks" you can do to make sure it is working:

Run:

$ ibv_devices     <= You should see a list of configured IB devices
$ ibv_devinfo     <= You should see "PORT_ACTIVE" in the output somewhere for each IB device
$ ifconfig ib0     <= if using standard infiniband
$ ifconfig eth0   <= if using RDMA over Converged ethernet

Furthermore, there are several latency/throughput utilities that come along with the OpenFabrics software stack you can run to make sure your two hosts are communicating with each other:

There's these commands:

$ ucmatose  [args...]
$ ibv_rc_pingpong [args ..]
$ rdma_server/rdma_client [args...]
Quoted 17 lines

I also used "0" instead of deus (the machine name).

The only thing that I did appart from intsalling librdmacm-devel was:

# cat /etc/udev/rules.d/80-infinibad.rules
KERNEL="rdma_cm", NAME="infiniband/%k", MODE="0666"

As per README. Something else I need to do to use the tcp implementations?

Later, Juan.

#52 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

In reply to Juan Quintela
Quoted 82 lines · Juan Quintela
Quoted 57 lines · Michael R. Hines
Quoted 39 lines · Paolo Bonzini

Il 25/06/2013 11:49, Juan Quintela ha scritto:

Quoted 38 lines
Quoted 25 lines · [email protected] wrote:

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 static void migrate_fd_cancel(MigrationState *s) · line 325

Quoted 5 lines
migration.c +0 -0
@@ -316,6 +321,7 @@ static void migrate_fd_cancel(MigrationState *s)
   {
       DPRINTF("cancelling migration\n");
   +    migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_CANCELLED);
       migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_CANCELLED);
   }

This chunk is wrong.

we can call qme_migrate_cancel() at any point, and it is going to be called normally from MIG_STATE_ACTIVE.

      migrate_set_satet(s, s->state,  MIG_STATE_CANCELLED)
Quoted 7 lines
Quoted 1 line

should do the trick. Or something like that, what do you think?

I don't like the three-arguments migrate_set_state, but I don't have any better idea.

With Juan's modification, it is fine (but not reviewed-by me :)). While you resend, the first 13 patches of v10 can be merged (pull request). You can then rebase the last three on top.

So, I should send a v11 before Juan applies and generates the pull request?

Did I understand correctly?

Quoted 5 lines

Michael, did you look at the "debugging/getting the protocol ready" mode where all pages are unpinned?

Paolo

Quoted 7 lines

We did not come up with a design on how such a mode would be exposed to the user. Implementing this in migration-rdma.c is just a few lines of code, but without a clear use case in this patch series, I've not chosen expose it to the user yet without some kind of agreement with you guys.

Recommendations?

Dunno. I have tried to use the thing:

I am using -incoming x-rdma:deus:4444

(qemu) char device redirected to /dev/pts/2 (label serial0)
librdmacm: Warning: couldn't read ABI version.
librdmacm: Warning: assuming: 4
librdmacm: Fatal: unable to get RDMA device list
RDMA ERROR: could not create rdma event channel
-incoming x-rdma:deus:4444: RDMA ERROR: could not create rdma event channel

I also used "0" instead of deus (the machine name).

The only thing that I did appart from intsalling librdmacm-devel was:

Quoted 9 lines
# cat /etc/udev/rules.d/80-infinibad.rules
KERNEL="rdma_cm", NAME="infiniband/%k", MODE="0666"

As per README. Something else I need to do to use the tcp implementations?

Later, Juan.

There's a simple bug found by Visilis affecting localhost migration which I believe also affects using '0' as a hostname in the migration.....

Both of these should be fixed in my next version. Will send out today. (I never tried migrating with 0.0.0.0 until now).

- Michael

Quoted 2 lines
#53 lore raw

Re: [Qemu-devel] [PATCH v11 14/15] rdma: introduce MIG_STATE_NONE and change MIG_STATE_SETUP state transition

In reply to Juan Quintela
Quoted 38 lines · Juan Quintela
Quoted 25 lines · [email protected] wrote:

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 static void migrate_fd_cancel(MigrationState *s) · line 326

Quoted 6 lines
migration.c +1 -0
@@ -316,6 +321,7 @@ static void migrate_fd_cancel(MigrationState *s)
  {
      DPRINTF("cancelling migration\n");
 
+    migrate_set_state(s, MIG_STATE_SETUP, MIG_STATE_CANCELLED);
      migrate_set_state(s, MIG_STATE_ACTIVE, MIG_STATE_CANCELLED);
  }

This chunk is wrong.

we can call qme_migrate_cancel() at any point, and it is going to be called normally from MIG_STATE_ACTIVE.

Quoted 8 lines
     migrate_set_satet(s, s->state,  MIG_STATE_CANCELLED)

should do the trick. Or something like that, what do you think?

Later, Juan.

Great idea, thank you.

- Michael

#54 lore raw

PATCH v11 15/15 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
index a3c6b55..2b75b28 100644
@@ -166,6 +166,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
index b5e413a..e41397e 100644
@@ -49,6 +49,7 @@ struct MigrationState
     int64_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
index 758d99d..bb412df 100644
@@ -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));
@@ -523,6 +528,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;
@@ -531,8 +537,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
index a30a728..b5e1e6b 100644
@@ -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 spent _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