qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wei Yang <richardw.yang@linux.intel.com>
To: Juan Quintela <quintela@redhat.com>
Cc: Laurent Vivier <lvivier@redhat.com>,
	Thomas Huth <thuth@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 8/8] multifd: rest of zlib compression
Date: Tue, 21 May 2019 11:11:10 +0800	[thread overview]
Message-ID: <20190521031110.GB24543@richard> (raw)
In-Reply-To: <20190515121544.4597-9-quintela@redhat.com>

On Wed, May 15, 2019 at 02:15:44PM +0200, Juan Quintela wrote:
>This is still a work in progress, but get everything sent as expected
>and it is faster than the code that is already there.

Generally, I prefer to merge this one with previous one.

>
>Signed-off-by: Juan Quintela <quintela@redhat.com>
>---
> migration/ram.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 104 insertions(+), 2 deletions(-)
>
>diff --git a/migration/ram.c b/migration/ram.c
>index fdb5bf07a5..efbb253c1a 100644
>--- a/migration/ram.c
>+++ b/migration/ram.c
>@@ -747,6 +747,100 @@ MultifdMethods multifd_none_ops = {
>     .recv_pages = none_recv_pages
> };
> 
>+/* Multifd zlib compression */
>+
>+static int zlib_send_prepare(MultiFDSendParams *p, uint32_t used)
>+{
>+    struct iovec *iov = p->pages->iov;
>+    z_stream *zs = &p->zs;
>+    uint32_t out_size = 0;
>+    int ret;
>+    int i;
>+
>+    for (i = 0; i < used; i++) {
>+        uint32_t available = p->zbuff_len - out_size;
>+        int flush = Z_NO_FLUSH;
>+
>+        if (i == used  - 1) {
>+            flush = Z_SYNC_FLUSH;
>+        }
>+
>+        zs->avail_in = iov[i].iov_len;
>+        zs->next_in = iov[i].iov_base;
>+
>+        zs->avail_out = available;
>+        zs->next_out = p->zbuff + out_size;
>+
>+        ret = deflate(zs, flush);
>+        if (ret != Z_OK) {
>+            printf("problem with deflate? %d\n", ret);
>+            qemu_mutex_unlock(&p->mutex);
>+            return -1;
>+        }
>+        out_size += available - zs->avail_out;
>+    }
>+    p->next_packet_size = out_size;
>+
>+    return 0;
>+}
>+
>+static int zlib_send_write(MultiFDSendParams *p, uint32_t used, Error **perr)
>+{
>+    return qio_channel_write_all(p->c, (void *)p->zbuff, p->next_packet_size,
>+                                 perr);
>+}
>+
>+static int zlib_recv_pages(MultiFDRecvParams *p, uint32_t used, Error **perr)
>+{
>+    uint32_t in_size = p->next_packet_size;
>+    uint32_t out_size = 0;
>+    uint32_t expected_size = used * qemu_target_page_size();
>+    z_stream *zs = &p->zs;
>+    int ret;
>+    int i;
>+
>+    ret = qio_channel_read_all(p->c, (void *)p->zbuff, in_size, perr);
>+
>+    if (ret != 0) {
>+        return ret;
>+    }
>+
>+    zs->avail_in = in_size;
>+    zs->next_in = p->zbuff;
>+
>+    for (i = 0; i < used; i++) {
>+        struct iovec *iov = &p->pages->iov[i];
>+        int flush = Z_NO_FLUSH;
>+
>+        if (i == used  - 1) {
>+            flush = Z_SYNC_FLUSH;
>+        }
>+
>+        zs->avail_out = iov->iov_len;
>+        zs->next_out = iov->iov_base;
>+
>+        ret = inflate(zs, flush);
>+        if (ret != Z_OK) {
>+            printf("%d: problem with inflate? %d\n", p->id, ret);
>+            qemu_mutex_unlock(&p->mutex);
>+            return ret;
>+        }
>+        out_size += iov->iov_len;
>+    }
>+    if (out_size != expected_size) {
>+        printf("out size %d expected size %d\n",
>+               out_size, expected_size);
>+        return -1;
>+    }
>+    return 0;
>+}
>+
>+MultifdMethods multifd_zlib_ops = {
>+    .send_prepare = zlib_send_prepare,
>+    .send_write = zlib_send_write,
>+    .recv_pages = zlib_recv_pages
>+};
>+
> static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp)
> {
>     MultiFDInit_t msg;
>@@ -1145,7 +1239,11 @@ static void *multifd_send_thread(void *opaque)
>     /* initial packet */
>     p->num_packets = 1;
> 
>-    multifd_send_state->ops = &multifd_none_ops;
>+    if (migrate_use_multifd_zlib()) {
>+        multifd_send_state->ops = &multifd_zlib_ops;
>+    } else {
>+        multifd_send_state->ops = &multifd_none_ops;
>+    }

Again, to manipulate a global variable in each thread is not a good idea.

This would be better to use an array to assign ops instead of *if*. In case
you would have several compress methods, the code would be difficult to read.

> 
>     while (true) {
>         qemu_sem_wait(&p->sem);
>@@ -1399,7 +1497,11 @@ static void *multifd_recv_thread(void *opaque)
>     trace_multifd_recv_thread_start(p->id);
>     rcu_register_thread();
> 
>-    multifd_recv_state->ops = &multifd_none_ops;
>+    if (migrate_use_multifd_zlib()) {
>+        multifd_recv_state->ops = &multifd_zlib_ops;
>+    } else {
>+        multifd_recv_state->ops = &multifd_none_ops;
>+    }
>     while (true) {
>         uint32_t used;
>         uint32_t flags;
>-- 
>2.21.0
>

-- 
Wei Yang
Help you, Help me


  reply	other threads:[~2019-05-21  3:12 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-15 12:15 [Qemu-devel] [PATCH v3 0/8] WIP: Multifd compression support Juan Quintela
2019-05-15 12:15 ` [Qemu-devel] [PATCH v3 1/8] migration: fix multifd_recv event typo Juan Quintela
2019-05-17 17:25   ` Dr. David Alan Gilbert
2019-05-20  6:38   ` Wei Yang
2019-05-15 12:15 ` [Qemu-devel] [PATCH v3 2/8] migration-test: rename parameter to parameter_int Juan Quintela
2019-05-20  6:43   ` Wei Yang
2019-05-15 12:15 ` [Qemu-devel] [PATCH v3 3/8] tests: Add migration multifd test Juan Quintela
2019-05-20  2:03   ` Wei Yang
2019-06-10  9:20     ` Juan Quintela
2019-05-20  6:48   ` Wei Yang
2019-06-10  9:23     ` Juan Quintela
2019-05-15 12:15 ` [Qemu-devel] [PATCH v3 4/8] migration-test: introduce functions to handle string parameters Juan Quintela
2019-05-15 12:15 ` [Qemu-devel] [PATCH v3 5/8] migration: Add multifd-compress parameter Juan Quintela
2019-05-15 15:34   ` Markus Armbruster
2019-06-10  9:38     ` Juan Quintela
2019-05-20  7:11   ` Wei Yang
2019-06-10  9:41     ` Juan Quintela
2019-05-20 12:53   ` Wei Yang
2019-06-10  9:42     ` Juan Quintela
2019-05-20 21:32   ` Wei Yang
2019-06-10  9:45     ` Juan Quintela
2019-05-15 12:15 ` [Qemu-devel] [PATCH v3 6/8] migration: Make none operations into its own structure Juan Quintela
2019-05-21  2:47   ` Wei Yang
2019-06-10  9:54     ` Juan Quintela
2019-05-29 16:34   ` Dr. David Alan Gilbert
2019-06-10  9:54     ` Juan Quintela
2019-06-12 11:54     ` Juan Quintela
2019-05-15 12:15 ` [Qemu-devel] [PATCH v3 7/8] multifd: Add zlib compression support Juan Quintela
2019-05-21  3:07   ` Wei Yang
2019-06-11 16:50     ` Juan Quintela
2019-05-29 16:48   ` Dr. David Alan Gilbert
2019-06-11 16:46     ` Juan Quintela
2019-05-15 12:15 ` [Qemu-devel] [PATCH v3 8/8] multifd: rest of zlib compression Juan Quintela
2019-05-21  3:11   ` Wei Yang [this message]
2019-06-11 16:54     ` Juan Quintela
2019-05-29 17:15   ` Dr. David Alan Gilbert
2019-06-12  8:33     ` Juan Quintela
2019-05-20  6:35 ` [Qemu-devel] [PATCH v3 0/8] WIP: Multifd compression support Wei Yang
2019-06-10 14:27   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190521031110.GB24543@richard \
    --to=richardw.yang@linux.intel.com \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).