From nobody Mon Feb 9 13:38:07 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487006800308286.0530729326264; Mon, 13 Feb 2017 09:26:40 -0800 (PST) Received: from localhost ([::1]:58366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKOb-0005TO-0O for importer@patchew.org; Mon, 13 Feb 2017 12:26:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKIQ-00087E-Gr for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:20:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKIO-00050V-Tp for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:20:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51980) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKIO-0004zF-LK for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:20:12 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB82461BAA for ; Mon, 13 Feb 2017 17:20:12 +0000 (UTC) Received: from emacs.mitica (ovpn-117-176.ams2.redhat.com [10.36.117.176]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94A024875E; Mon, 13 Feb 2017 17:20:11 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 13 Feb 2017 18:19:45 +0100 Message-Id: <1487006388-7966-10-git-send-email-quintela@redhat.com> In-Reply-To: <1487006388-7966-1-git-send-email-quintela@redhat.com> References: <1487006388-7966-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 13 Feb 2017 17:20:12 +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] [PULL 09/12] migration: Create thread infrastructure for multifd send 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: amit.shah@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 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 transmiting things through the main thread. Signed-off-by: Juan Quintela -- Move synchronization to use semaphores, as paolo suggestion. --- migration/ram.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 45c46cb..f7df6cb 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -392,17 +392,25 @@ void migrate_compress_threads_create(void) /* Multiple fd's */ struct MultiFDSendParams { + /* not changed */ QemuThread thread; QIOChannel *c; QemuSemaphore sem; QemuSemaphore init; QemuMutex mutex; + /* protected by param mutex */ bool quit; + uint8_t *address; + /* protected by multifd mutex */ + bool done; }; typedef struct MultiFDSendParams MultiFDSendParams; static MultiFDSendParams *multifd_send; +QemuMutex multifd_send_mutex; +QemuSemaphore multifd_send_sem; + static void *multifd_send_thread(void *opaque) { MultiFDSendParams *params =3D opaque; @@ -410,6 +418,7 @@ static void *multifd_send_thread(void *opaque) qio_channel_write(params->c, &start, 1, &error_abort); qemu_sem_post(¶ms->init); + qemu_sem_post(&multifd_send_sem); while (true) { qemu_mutex_lock(¶ms->mutex); @@ -417,6 +426,15 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_unlock(¶ms->mutex); break; } + if (params->address) { + params->address =3D 0; + qemu_mutex_unlock(¶ms->mutex); + qemu_mutex_lock(&multifd_send_mutex); + params->done =3D true; + qemu_mutex_unlock(&multifd_send_mutex); + qemu_sem_post(&multifd_send_sem); + continue; + } qemu_mutex_unlock(¶ms->mutex); qemu_sem_wait(¶ms->sem); } @@ -471,6 +489,8 @@ void migrate_multifd_send_threads_create(void) } thread_count =3D migrate_multifd_threads(); multifd_send =3D g_new0(MultiFDSendParams, thread_count); + qemu_mutex_init(&multifd_send_mutex); + qemu_sem_init(&multifd_send_sem, 0); for (i =3D 0; i < thread_count; i++) { char thread_name[15]; MultiFDSendParams *p =3D &multifd_send[i]; @@ -479,6 +499,8 @@ void migrate_multifd_send_threads_create(void) qemu_sem_init(&p->sem, 0); qemu_sem_init(&p->init, 0); p->quit =3D false; + p->done =3D true; + p->address =3D 0; p->c =3D socket_send_channel_create(); if (!p->c) { error_report("Error creating a send channel"); @@ -491,6 +513,28 @@ void migrate_multifd_send_threads_create(void) } } +static int multifd_send_page(uint8_t *address) +{ + int i, thread_count; + + thread_count =3D migrate_multifd_threads(); + qemu_sem_wait(&multifd_send_sem); + qemu_mutex_lock(&multifd_send_mutex); + for (i =3D 0; i < thread_count; i++) { + if (multifd_send[i].done) { + multifd_send[i].done =3D false; + break; + } + } + qemu_mutex_unlock(&multifd_send_mutex); + qemu_mutex_lock(&multifd_send[i].mutex); + multifd_send[i].address =3D address; + qemu_mutex_unlock(&multifd_send[i].mutex); + qemu_sem_post(&multifd_send[i].sem); + + return 0; +} + struct MultiFDRecvParams { QemuThread thread; QIOChannel *c; @@ -1023,6 +1067,7 @@ static int ram_multifd_page(QEMUFile *f, PageSearchSt= atus *pss, *bytes_transferred +=3D save_page_header(f, block, offset | RAM_SAVE_FLAG_MULTIFD_PAGE= ); qemu_put_buffer(f, p, TARGET_PAGE_SIZE); + multifd_send_page(p); *bytes_transferred +=3D TARGET_PAGE_SIZE; pages =3D 1; acct_info.norm_pages++; --=20 2.7.4