From patchwork Thu Jun 6 08:34:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 10978835 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C90A317D2 for ; Thu, 6 Jun 2019 08:47:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BACAD203B9 for ; Thu, 6 Jun 2019 08:47:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF32F287C5; Thu, 6 Jun 2019 08:47: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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5D14A203B9 for ; Thu, 6 Jun 2019 08:47:48 +0000 (UTC) Received: from localhost ([127.0.0.1]:56636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYo3n-0008DD-N0 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 06 Jun 2019 04:47:47 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hYnyf-0003mZ-6q for qemu-devel@nongnu.org; Thu, 06 Jun 2019 04:42:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hYnsJ-0003W5-Ie for qemu-devel@nongnu.org; Thu, 06 Jun 2019 04:35:56 -0400 Received: from mga14.intel.com ([192.55.52.115]:4990) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hYnsJ-0003TJ-Ap for qemu-devel@nongnu.org; Thu, 06 Jun 2019 04:35:55 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jun 2019 01:35:55 -0700 X-ExtLoop1: 1 Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by fmsmga001.fm.intel.com with ESMTP; 06 Jun 2019 01:35:54 -0700 From: Wei Yang To: qemu-devel@nongnu.org Date: Thu, 6 Jun 2019 16:34:58 +0800 Message-Id: <20190606083501.2087-4-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190606083501.2087-1-richardw.yang@linux.intel.com> References: <20190606083501.2087-1-richardw.yang@linux.intel.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.115 Subject: [Qemu-devel] [PATCH 3/6] migration/multifd: use sync field to synchronize send threads 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: Wei Yang , dgilbert@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add a field in MultiFDSendParams to indicate there is a request to synchronize send threads. By doing so, send_thread will just post sem_sync on synchronization request and channels_ready will not *overflow*. Signed-off-by: Wei Yang --- migration/ram.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index f9e53ac413..9982930392 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -640,6 +640,8 @@ typedef struct { QemuMutex mutex; /* is this channel thread running */ bool running; + /* should sync this channel */ + bool sync; /* should this thread finish */ bool quit; /* thread has work to do */ @@ -1065,8 +1067,7 @@ static void multifd_send_sync_main(void) qemu_mutex_lock(&p->mutex); p->packet_num = multifd_send_state->packet_num++; - p->flags |= MULTIFD_FLAG_SYNC; - p->pending_job++; + p->sync = true; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); } @@ -1129,10 +1130,27 @@ static void *multifd_send_thread(void *opaque) p->pending_job--; qemu_mutex_unlock(&p->mutex); - if (flags & MULTIFD_FLAG_SYNC) { - qemu_sem_post(&multifd_send_state->sem_sync); - } qemu_sem_post(&multifd_send_state->channels_ready); + } else if (p->sync) { + uint64_t packet_num = p->packet_num; + uint32_t flags = p->flags; + assert(!p->pages->used); + + p->flags |= MULTIFD_FLAG_SYNC; + multifd_send_fill_packet(p); + p->sync = false; + qemu_mutex_unlock(&p->mutex); + + trace_multifd_send(p->id, packet_num, 0, flags | MULTIFD_FLAG_SYNC, + p->next_packet_size); + + ret = qio_channel_write_all(p->c, (void *)p->packet, + p->packet_len, &local_err); + if (ret != 0) { + break; + } + + qemu_sem_post(&multifd_send_state->sem_sync); } else if (p->quit) { qemu_mutex_unlock(&p->mutex); break; @@ -1196,7 +1214,7 @@ int multifd_save_setup(void) qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); - p->quit = false; + p->sync = p->quit = false; p->pending_job = 0; p->id = i; p->pages = multifd_pages_init(page_count);