thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
1be5c7
From 1181a9cbcaf37a82aa7bf117ef209f554b8c4a71 Mon Sep 17 00:00:00 2001
1be5c7
From: Juan Quintela <quintela@redhat.com>
1be5c7
Date: Wed, 18 May 2022 02:52:24 -0300
1be5c7
Subject: [PATCH 11/37] multifd: Move iov from pages to params
1be5c7
MIME-Version: 1.0
1be5c7
Content-Type: text/plain; charset=UTF-8
1be5c7
Content-Transfer-Encoding: 8bit
1be5c7
1be5c7
RH-Author: Leonardo Brás <leobras@redhat.com>
1be5c7
RH-MergeRequest: 191: MSG_ZEROCOPY + Multifd @ rhel8.7
1be5c7
RH-Commit: [11/26] 24dff3ef68cf3327811242193502319ed3e3940a
1be5c7
RH-Bugzilla: 2072049
1be5c7
RH-Acked-by: Peter Xu <peterx@redhat.com>
1be5c7
RH-Acked-by: Daniel P. Berrangé <berrange@redhat.com>
1be5c7
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1be5c7
1be5c7
This will allow us to reduce the number of system calls on the next patch.
1be5c7
1be5c7
Signed-off-by: Juan Quintela <quintela@redhat.com>
1be5c7
(cherry picked from commit 226468ba3dea950ab4bb0b729878dde25812da1c)
1be5c7
Signed-off-by: Leonardo Bras <leobras@redhat.com>
1be5c7
---
1be5c7
 migration/multifd.c | 34 ++++++++++++++++++++++++----------
1be5c7
 migration/multifd.h |  8 ++++++--
1be5c7
 2 files changed, 30 insertions(+), 12 deletions(-)
1be5c7
1be5c7
diff --git a/migration/multifd.c b/migration/multifd.c
1be5c7
index d0d19470f9..5004f394aa 100644
1be5c7
--- a/migration/multifd.c
1be5c7
+++ b/migration/multifd.c
1be5c7
@@ -86,7 +86,16 @@ static void nocomp_send_cleanup(MultiFDSendParams *p, Error **errp)
1be5c7
  */
1be5c7
 static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp)
1be5c7
 {
1be5c7
-    p->next_packet_size = p->pages->num * qemu_target_page_size();
1be5c7
+    MultiFDPages_t *pages = p->pages;
1be5c7
+    size_t page_size = qemu_target_page_size();
1be5c7
+
1be5c7
+    for (int i = 0; i < p->pages->num; i++) {
1be5c7
+        p->iov[p->iovs_num].iov_base = pages->block->host + pages->offset[i];
1be5c7
+        p->iov[p->iovs_num].iov_len = page_size;
1be5c7
+        p->iovs_num++;
1be5c7
+    }
1be5c7
+
1be5c7
+    p->next_packet_size = p->pages->num * page_size;
1be5c7
     p->flags |= MULTIFD_FLAG_NOCOMP;
1be5c7
     return 0;
1be5c7
 }
1be5c7
@@ -104,7 +113,7 @@ static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp)
1be5c7
  */
1be5c7
 static int nocomp_send_write(MultiFDSendParams *p, uint32_t used, Error **errp)
1be5c7
 {
1be5c7
-    return qio_channel_writev_all(p->c, p->pages->iov, used, errp);
1be5c7
+    return qio_channel_writev_all(p->c, p->iov, p->iovs_num, errp);
1be5c7
 }
1be5c7
 
1be5c7
 /**
1be5c7
@@ -146,13 +155,18 @@ static void nocomp_recv_cleanup(MultiFDRecvParams *p)
1be5c7
 static int nocomp_recv_pages(MultiFDRecvParams *p, Error **errp)
1be5c7
 {
1be5c7
     uint32_t flags = p->flags & MULTIFD_FLAG_COMPRESSION_MASK;
1be5c7
+    size_t page_size = qemu_target_page_size();
1be5c7
 
1be5c7
     if (flags != MULTIFD_FLAG_NOCOMP) {
1be5c7
         error_setg(errp, "multifd %u: flags received %x flags expected %x",
1be5c7
                    p->id, flags, MULTIFD_FLAG_NOCOMP);
1be5c7
         return -1;
1be5c7
     }
1be5c7
-    return qio_channel_readv_all(p->c, p->pages->iov, p->pages->num, errp);
1be5c7
+    for (int i = 0; i < p->pages->num; i++) {
1be5c7
+        p->iov[i].iov_base = p->pages->block->host + p->pages->offset[i];
1be5c7
+        p->iov[i].iov_len = page_size;
1be5c7
+    }
1be5c7
+    return qio_channel_readv_all(p->c, p->iov, p->pages->num, errp);
1be5c7
 }
1be5c7
 
1be5c7
 static MultiFDMethods multifd_nocomp_ops = {
1be5c7
@@ -242,7 +256,6 @@ static MultiFDPages_t *multifd_pages_init(size_t size)
1be5c7
     MultiFDPages_t *pages = g_new0(MultiFDPages_t, 1);
1be5c7
 
1be5c7
     pages->allocated = size;
1be5c7
-    pages->iov = g_new0(struct iovec, size);
1be5c7
     pages->offset = g_new0(ram_addr_t, size);
1be5c7
 
1be5c7
     return pages;
1be5c7
@@ -254,8 +267,6 @@ static void multifd_pages_clear(MultiFDPages_t *pages)
1be5c7
     pages->allocated = 0;
1be5c7
     pages->packet_num = 0;
1be5c7
     pages->block = NULL;
1be5c7
-    g_free(pages->iov);
1be5c7
-    pages->iov = NULL;
1be5c7
     g_free(pages->offset);
1be5c7
     pages->offset = NULL;
1be5c7
     g_free(pages);
1be5c7
@@ -365,8 +376,6 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
1be5c7
             return -1;
1be5c7
         }
1be5c7
         p->pages->offset[i] = offset;
1be5c7
-        p->pages->iov[i].iov_base = block->host + offset;
1be5c7
-        p->pages->iov[i].iov_len = page_size;
1be5c7
     }
1be5c7
 
1be5c7
     return 0;
1be5c7
@@ -470,8 +479,6 @@ int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset)
1be5c7
 
1be5c7
     if (pages->block == block) {
1be5c7
         pages->offset[pages->num] = offset;
1be5c7
-        pages->iov[pages->num].iov_base = block->host + offset;
1be5c7
-        pages->iov[pages->num].iov_len = qemu_target_page_size();
1be5c7
         pages->num++;
1be5c7
 
1be5c7
         if (pages->num < pages->allocated) {
1be5c7
@@ -564,6 +571,8 @@ void multifd_save_cleanup(void)
1be5c7
         p->packet_len = 0;
1be5c7
         g_free(p->packet);
1be5c7
         p->packet = NULL;
1be5c7
+        g_free(p->iov);
1be5c7
+        p->iov = NULL;
1be5c7
         multifd_send_state->ops->send_cleanup(p, &local_err);
1be5c7
         if (local_err) {
1be5c7
             migrate_set_error(migrate_get_current(), local_err);
1be5c7
@@ -651,6 +660,7 @@ static void *multifd_send_thread(void *opaque)
1be5c7
             uint32_t used = p->pages->num;
1be5c7
             uint64_t packet_num = p->packet_num;
1be5c7
             uint32_t flags = p->flags;
1be5c7
+            p->iovs_num = 0;
1be5c7
 
1be5c7
             if (used) {
1be5c7
                 ret = multifd_send_state->ops->send_prepare(p, &local_err);
1be5c7
@@ -919,6 +929,7 @@ int multifd_save_setup(Error **errp)
1be5c7
         p->packet->version = cpu_to_be32(MULTIFD_VERSION);
1be5c7
         p->name = g_strdup_printf("multifdsend_%d", i);
1be5c7
         p->tls_hostname = g_strdup(s->hostname);
1be5c7
+        p->iov = g_new0(struct iovec, page_count);
1be5c7
         socket_send_channel_create(multifd_new_send_channel_async, p);
1be5c7
     }
1be5c7
 
1be5c7
@@ -1018,6 +1029,8 @@ int multifd_load_cleanup(Error **errp)
1be5c7
         p->packet_len = 0;
1be5c7
         g_free(p->packet);
1be5c7
         p->packet = NULL;
1be5c7
+        g_free(p->iov);
1be5c7
+        p->iov = NULL;
1be5c7
         multifd_recv_state->ops->recv_cleanup(p);
1be5c7
     }
1be5c7
     qemu_sem_destroy(&multifd_recv_state->sem_sync);
1be5c7
@@ -1158,6 +1171,7 @@ int multifd_load_setup(Error **errp)
1be5c7
                       + sizeof(uint64_t) * page_count;
1be5c7
         p->packet = g_malloc0(p->packet_len);
1be5c7
         p->name = g_strdup_printf("multifdrecv_%d", i);
1be5c7
+        p->iov = g_new0(struct iovec, page_count);
1be5c7
     }
1be5c7
 
1be5c7
     for (i = 0; i < thread_count; i++) {
1be5c7
diff --git a/migration/multifd.h b/migration/multifd.h
1be5c7
index e57adc783b..c3f18af364 100644
1be5c7
--- a/migration/multifd.h
1be5c7
+++ b/migration/multifd.h
1be5c7
@@ -62,8 +62,6 @@ typedef struct {
1be5c7
     uint64_t packet_num;
1be5c7
     /* offset of each page */
1be5c7
     ram_addr_t *offset;
1be5c7
-    /* pointer to each page */
1be5c7
-    struct iovec *iov;
1be5c7
     RAMBlock *block;
1be5c7
 } MultiFDPages_t;
1be5c7
 
1be5c7
@@ -110,6 +108,10 @@ typedef struct {
1be5c7
     uint64_t num_pages;
1be5c7
     /* syncs main thread and channels */
1be5c7
     QemuSemaphore sem_sync;
1be5c7
+    /* buffers to send */
1be5c7
+    struct iovec *iov;
1be5c7
+    /* number of iovs used */
1be5c7
+    uint32_t iovs_num;
1be5c7
     /* used for compression methods */
1be5c7
     void *data;
1be5c7
 }  MultiFDSendParams;
1be5c7
@@ -149,6 +151,8 @@ typedef struct {
1be5c7
     uint64_t num_pages;
1be5c7
     /* syncs main thread and channels */
1be5c7
     QemuSemaphore sem_sync;
1be5c7
+    /* buffers to recv */
1be5c7
+    struct iovec *iov;
1be5c7
     /* used for de-compression methods */
1be5c7
     void *data;
1be5c7
 } MultiFDRecvParams;
1be5c7
-- 
1be5c7
2.35.3
1be5c7