From patchwork Fri Oct 21 19:42:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 9390039 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3286460762 for ; Fri, 21 Oct 2016 20:01:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 218712A291 for ; Fri, 21 Oct 2016 20:01:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 162912A295; Fri, 21 Oct 2016 20:01:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AD8582A291 for ; Fri, 21 Oct 2016 20:01:05 +0000 (UTC) Received: from localhost ([::1]:34183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxg00-0003e8-RN for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Oct 2016 16:01:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxfiC-0005Ii-TD for qemu-devel@nongnu.org; Fri, 21 Oct 2016 15:42:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxfi8-0007XL-0R for qemu-devel@nongnu.org; Fri, 21 Oct 2016 15:42:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47938) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bxfi7-0007Wz-PO for qemu-devel@nongnu.org; Fri, 21 Oct 2016 15:42:35 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F72AC04B923 for ; Fri, 21 Oct 2016 19:42:35 +0000 (UTC) Received: from emacs.mitica (ovpn-116-122.ams2.redhat.com [10.36.116.122]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9LJgLrf018033; Fri, 21 Oct 2016 15:42:33 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 21 Oct 2016 21:42:10 +0200 Message-Id: <1477078935-7182-9-git-send-email-quintela@redhat.com> In-Reply-To: <1477078935-7182-1-git-send-email-quintela@redhat.com> References: <1477078935-7182-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 21 Oct 2016 19:42:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/13] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- migration/ram.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 44b9380..0098d33 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -399,17 +399,25 @@ void migrate_compress_threads_create(void) /* Multiple fd's */ struct MultiFDSendParams { + /* not changed */ QemuThread thread; + QIOChannel *c; QemuCond cond; QemuMutex mutex; + /* protected by param mutex */ bool quit; bool started; - QIOChannel *c; + uint8_t *address; + /* protected by multifd mutex */ + bool done; }; typedef struct MultiFDSendParams MultiFDSendParams; static MultiFDSendParams *multifd_send; +QemuMutex multifd_send_mutex; +QemuCond multifd_send_cond; + static void *multifd_send_thread(void *opaque) { MultiFDSendParams *params = opaque; @@ -423,7 +431,17 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_lock(¶ms->mutex); while (!params->quit){ - qemu_cond_wait(¶ms->cond, ¶ms->mutex); + if (params->address) { + params->address = 0; + qemu_mutex_unlock(¶ms->mutex); + qemu_mutex_lock(&multifd_send_mutex); + params->done = true; + qemu_cond_signal(&multifd_send_cond); + qemu_mutex_unlock(&multifd_send_mutex); + qemu_mutex_lock(¶ms->mutex); + } else { + qemu_cond_wait(¶ms->cond, ¶ms->mutex); + } } qemu_mutex_unlock(¶ms->mutex); @@ -471,11 +489,15 @@ void migrate_multifd_send_threads_create(void) } thread_count = migrate_multifd_threads(); multifd_send = g_new0(MultiFDSendParams, thread_count); + qemu_mutex_init(&multifd_send_mutex); + qemu_cond_init(&multifd_send_cond); for (i = 0; i < thread_count; i++) { qemu_mutex_init(&multifd_send[i].mutex); qemu_cond_init(&multifd_send[i].cond); multifd_send[i].quit = false; multifd_send[i].started = false; + multifd_send[i].done = true; + multifd_send[i].address = 0; multifd_send[i].c = socket_send_channel_create(); if(!multifd_send[i].c) { printf("Error creating a send channel"); @@ -492,6 +514,34 @@ void migrate_multifd_send_threads_create(void) } } +static int multifd_send_page(uint8_t *address) +{ + int i, thread_count; + bool found = false; + + thread_count = migrate_multifd_threads(); + qemu_mutex_lock(&multifd_send_mutex); + while (!found) { + for (i = 0; i < thread_count; i++) { + if (multifd_send[i].done) { + multifd_send[i].done = false; + found = true; + break; + } + } + if (!found) { + qemu_cond_wait(&multifd_send_cond, &multifd_send_mutex); + } + } + qemu_mutex_unlock(&multifd_send_mutex); + qemu_mutex_lock(&multifd_send[i].mutex); + multifd_send[i].address = address; + qemu_cond_signal(&multifd_send[i].cond); + qemu_mutex_unlock(&multifd_send[i].mutex); + + return 0; +} + struct MultiFDRecvParams { QemuThread thread; QemuCond cond; @@ -1020,6 +1070,7 @@ static int ram_multifd_page(QEMUFile *f, PageSearchStatus *pss, *bytes_transferred += 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 += TARGET_PAGE_SIZE; pages = 1; acct_info.norm_pages++;