From nobody Tue Feb 10 15:01:07 2026 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507114546480537.5931289597283; Wed, 4 Oct 2017 03:55:46 -0700 (PDT) Received: from localhost ([::1]:34311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhKm-0003Ag-RR for importer@patchew.org; Wed, 04 Oct 2017 06:55:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55074) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzhCa-0004xG-O1 for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzhCZ-0002xg-KP for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33297) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzhCZ-0002wU-CO for qemu-devel@nongnu.org; Wed, 04 Oct 2017 06:46:55 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 59C87820E5 for ; Wed, 4 Oct 2017 10:46:54 +0000 (UTC) Received: from secure.mitica (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id E744E5D9CB; Wed, 4 Oct 2017 10:46:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 59C87820E5 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=quintela@redhat.com From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 4 Oct 2017 12:46:31 +0200 Message-Id: <20171004104636.7963-8-quintela@redhat.com> In-Reply-To: <20171004104636.7963-1-quintela@redhat.com> References: <20171004104636.7963-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 04 Oct 2017 10:46:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v9 07/12] migration: Create thread infrastructure for multifd recv side X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, dgilbert@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We make the locking and the transfer of information specific, even if we are still receiving things through the main thread. Signed-off-by: Juan Quintela -- We split when we create the main channel and where we start the main migration thread, so we wait for the creation of the other threads. Use multifd_clear_pages(). Don't remove object_unref() We use correctly the channel numbres --- migration/migration.c | 7 +++--- migration/migration.h | 1 + migration/ram.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++= ---- migration/socket.c | 3 +++ 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index ee98c50d8c..1e7c537954 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -388,7 +388,7 @@ static void migration_incoming_setup(QEMUFile *f) qemu_file_set_blocking(f, false); } =20 -static void migration_incoming_process(void) +void migration_incoming_process(void) { Coroutine *co =3D qemu_coroutine_create(process_incoming_migration_co,= NULL); qemu_coroutine_enter(co); @@ -406,9 +406,10 @@ void migration_ioc_process_incoming(QIOChannel *ioc) =20 if (!mis->from_src_file) { QEMUFile *f =3D qemu_fopen_channel_input(ioc); - migration_fd_process_incoming(f); + migration_incoming_setup(f); + return; } - /* We still only have a single channel. Nothing to do here yet */ + multifd_new_channel(ioc); } =20 /** diff --git a/migration/migration.h b/migration/migration.h index cc196cc87f..a3db60a2a1 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -158,6 +158,7 @@ void migrate_set_state(int *state, int old_state, int n= ew_state); =20 void migration_fd_process_incoming(QEMUFile *f); void migration_ioc_process_incoming(QIOChannel *ioc); +void migration_incoming_process(void); =20 bool migration_has_all_channels(void); =20 diff --git a/migration/ram.c b/migration/ram.c index 288201e360..745da2971d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -597,13 +597,18 @@ static uint16_t multifd_send_page(uint8_t *address, b= ool last_page) } =20 struct MultiFDRecvParams { + /* not changed */ uint8_t id; char *name; QemuThread thread; QIOChannel *c; + QemuSemaphore ready; QemuSemaphore sem; QemuMutex mutex; + /* proteced by param mutex */ bool quit; + multifd_pages_t pages; + bool done; }; typedef struct MultiFDRecvParams MultiFDRecvParams; =20 @@ -613,6 +618,7 @@ struct { int count; /* Should we finish */ bool quit; + multifd_pages_t pages; } *multifd_recv_state; =20 static void terminate_multifd_recv_threads(Error *errp) @@ -634,6 +640,7 @@ static void terminate_multifd_recv_threads(Error *errp) p->quit =3D true; qemu_sem_post(&p->sem); qemu_mutex_unlock(&p->mutex); + multifd_clear_pages(&p->pages); } } =20 @@ -658,6 +665,7 @@ int multifd_load_cleanup(Error **errp) } g_free(multifd_recv_state->params); multifd_recv_state->params =3D NULL; + multifd_clear_pages(&multifd_recv_state->pages); g_free(multifd_recv_state); multifd_recv_state =3D NULL; =20 @@ -668,12 +676,20 @@ static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *p =3D opaque; =20 + qemu_sem_post(&p->ready); while (true) { qemu_mutex_lock(&p->mutex); if (p->quit) { qemu_mutex_unlock(&p->mutex); break; } + if (p->pages.num) { + p->pages.num =3D 0; + p->done =3D true; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->ready); + continue; + } qemu_mutex_unlock(&p->mutex); qemu_sem_wait(&p->sem); } @@ -714,13 +730,21 @@ void multifd_new_channel(QIOChannel *ioc) } qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); + qemu_sem_init(&p->ready, 0); p->quit =3D false; p->id =3D msg.id; + p->done =3D false; + multifd_init_pages(&p->pages); p->c =3D ioc; multifd_recv_state->count++; p->name =3D g_strdup_printf("multifdrecv_%d", msg.id); + object_ref(OBJECT(ioc)); + qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, QEMU_THREAD_JOINABLE); + if (multifd_recv_state->count =3D=3D migrate_multifd_channels()) { + migration_incoming_process(); + } } =20 int multifd_load_setup(void) @@ -735,6 +759,7 @@ int multifd_load_setup(void) multifd_recv_state->params =3D g_new0(MultiFDRecvParams, thread_count); multifd_recv_state->count =3D 0; multifd_recv_state->quit =3D false; + multifd_init_pages(&multifd_recv_state->pages); return 0; } =20 @@ -743,6 +768,36 @@ int multifd_created_channels(void) return multifd_recv_state->count; } =20 +static void multifd_recv_page(uint8_t *address, uint16_t fd_num) +{ + int thread_count; + MultiFDRecvParams *p; + multifd_pages_t *pages =3D &multifd_recv_state->pages; + + pages->iov[pages->num].iov_base =3D address; + pages->iov[pages->num].iov_len =3D TARGET_PAGE_SIZE; + pages->num++; + + if (fd_num =3D=3D MULTIFD_CONTINUE) { + return; + } + + thread_count =3D migrate_multifd_channels(); + assert(fd_num < thread_count); + p =3D &multifd_recv_state->params[fd_num]; + + qemu_sem_wait(&p->ready); + + qemu_mutex_lock(&p->mutex); + p->done =3D false; + iov_copy(p->pages.iov, pages->num, pages->iov, pages->num, 0, + iov_size(pages->iov, pages->num)); + p->pages.num =3D pages->num; + pages->num =3D 0; + qemu_mutex_unlock(&p->mutex); + qemu_sem_post(&p->sem); +} + /** * save_page_header: write page header to wire * @@ -3060,10 +3115,7 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) =20 case RAM_SAVE_FLAG_MULTIFD_PAGE: fd_num =3D qemu_get_be16(f); - if (fd_num !=3D 0) { - /* this is yet an unused variable, changed later */ - fd_num =3D fd_num; - } + multifd_recv_page(host, fd_num); qemu_get_buffer(f, host, TARGET_PAGE_SIZE); break; =20 diff --git a/migration/socket.c b/migration/socket.c index 22fb05edc8..debe972ee8 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -186,6 +186,9 @@ out: if (migration_has_all_channels()) { /* Close listening socket as its no longer needed */ qio_channel_close(ioc, NULL); + if (!migrate_use_multifd()) { + migration_incoming_process(); + } return G_SOURCE_REMOVE; } else { return G_SOURCE_CONTINUE; --=20 2.13.5