From patchwork Fri Oct 21 19:42:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 9390029 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 B79B260231 for ; Fri, 21 Oct 2016 19:52:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A24E72A1B3 for ; Fri, 21 Oct 2016 19:52:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95B1E2A276; Fri, 21 Oct 2016 19:52:48 +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 0968A2A1B3 for ; Fri, 21 Oct 2016 19:52:47 +0000 (UTC) Received: from localhost ([::1]:34129 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxfrz-0004tq-0T for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Oct 2016 15:52:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxfiC-0005Ik-UX 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 1bxfiB-0007Z5-0O for qemu-devel@nongnu.org; Fri, 21 Oct 2016 15:42:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47960) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bxfiA-0007Yh-P9 for qemu-devel@nongnu.org; Fri, 21 Oct 2016 15:42:38 -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 09001C04B332 for ; Fri, 21 Oct 2016 19:42:38 +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 u9LJgLrh018033; Fri, 21 Oct 2016 15:42:36 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 21 Oct 2016 21:42:12 +0200 Message-Id: <1477078935-7182-11-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:38 +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 10/13] 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: 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 receiving things through the main thread. Signed-off-by: Juan Quintela --- migration/ram.c | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 8de9b0d..294a99e 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -543,17 +543,25 @@ static int multifd_send_page(uint8_t *address) } struct MultiFDRecvParams { + /* not changed */ QemuThread thread; + QIOChannel *c; QemuCond cond; QemuMutex mutex; + /* proteced by param mutex */ bool quit; bool started; - QIOChannel *c; + uint8_t *address; + /* proteced by multifd mutex */ + bool done; }; typedef struct MultiFDRecvParams MultiFDRecvParams; static MultiFDRecvParams *multifd_recv; +QemuMutex multifd_recv_mutex; +QemuCond multifd_recv_cond; + static void *multifd_recv_thread(void *opaque) { MultiFDRecvParams *params = opaque; @@ -567,7 +575,17 @@ static void *multifd_recv_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_recv_mutex); + params->done = true; + qemu_cond_signal(&multifd_recv_cond); + qemu_mutex_unlock(&multifd_recv_mutex); + qemu_mutex_lock(¶ms->mutex); + } else { + qemu_cond_wait(¶ms->cond, ¶ms->mutex); + } } qemu_mutex_unlock(¶ms->mutex); @@ -620,8 +638,9 @@ void migrate_multifd_recv_threads_create(void) qemu_cond_init(&multifd_recv[i].cond); multifd_recv[i].quit = false; multifd_recv[i].started = false; + multifd_recv[i].done = true; + multifd_recv[i].address = 0; multifd_recv[i].c = socket_recv_channel_create(); - if(!multifd_recv[i].c) { printf("Error creating a recv channel"); exit(0); @@ -637,6 +656,27 @@ void migrate_multifd_recv_threads_create(void) } } +static void multifd_recv_page(uint8_t *address, int fd_num) +{ + int thread_count; + MultiFDRecvParams *params; + + thread_count = migrate_multifd_threads(); + assert(fd_num < thread_count); + params = &multifd_recv[fd_num]; + + qemu_mutex_lock(&multifd_recv_mutex); + while (!params->done) { + qemu_cond_wait(&multifd_recv_cond, &multifd_recv_mutex); + } + params->done = false; + qemu_mutex_unlock(&multifd_recv_mutex); + qemu_mutex_lock(¶ms->mutex); + params->address = address; + qemu_cond_signal(¶ms->cond); + qemu_mutex_unlock(¶ms->mutex); +} + /** * save_page_header: Write page header to wire * @@ -2852,6 +2892,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) /* this is yet an unused variable, changed later */ fd_num = 0; } + multifd_recv_page(host, fd_num); qemu_get_buffer(f, host, TARGET_PAGE_SIZE); break;