From patchwork Sat Oct 26 00:45:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 1184535 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 470NcP3dDKz9sPV for ; Sat, 26 Oct 2019 12:26:45 +1100 (AEDT) Received: from localhost ([::1]:37826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOAqp-0000bx-9m for incoming@patchwork.ozlabs.org; Fri, 25 Oct 2019 21:26:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54967) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOADB-0002Zz-F7 for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iOADA-0004kg-DV for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:45 -0400 Received: from mga01.intel.com ([192.55.52.88]:5552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iOADA-0004k9-66 for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:44 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2019 17:45:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,230,1569308400"; d="scan'208";a="204705106" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by FMSMGA003.fm.intel.com with ESMTP; 25 Oct 2019 17:45:42 -0700 From: Wei Yang To: quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v2 1/6] migration/multifd: move Params update and pages cleanup into multifd_send_fill_packet() Date: Sat, 26 Oct 2019 08:45:15 +0800 Message-Id: <20191026004520.5515-2-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191026004520.5515-1-richardw.yang@linux.intel.com> References: <20191026004520.5515-1-richardw.yang@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Wei Yang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Fill data and update/cleanup related field in one place. Also make the code a little clean. Signed-off-by: Wei Yang Reviewed-by: Juan Quintela --- migration/ram.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 5876054195..35f147388b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -789,15 +789,16 @@ static void multifd_pages_clear(MultiFDPages_t *pages) g_free(pages); } -static void multifd_send_fill_packet(MultiFDSendParams *p) +static void multifd_send_fill_packet(MultiFDSendParams *p, uint32_t used) { MultiFDPacket_t *packet = p->packet; + uint32_t next_packet_size = used * qemu_target_page_size(); int i; packet->flags = cpu_to_be32(p->flags); packet->pages_alloc = cpu_to_be32(p->pages->allocated); packet->pages_used = cpu_to_be32(p->pages->used); - packet->next_packet_size = cpu_to_be32(p->next_packet_size); + packet->next_packet_size = cpu_to_be32(next_packet_size); packet->packet_num = cpu_to_be64(p->packet_num); if (p->pages->block) { @@ -807,6 +808,13 @@ static void multifd_send_fill_packet(MultiFDSendParams *p) for (i = 0; i < p->pages->used; i++) { packet->offset[i] = cpu_to_be64(p->pages->offset[i]); } + + p->next_packet_size = next_packet_size; + p->flags = 0; + p->num_packets++; + p->num_pages += used; + p->pages->used = 0; + p->pages->block = NULL; } static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) @@ -1109,13 +1117,7 @@ static void *multifd_send_thread(void *opaque) uint64_t packet_num = p->packet_num; flags = p->flags; - p->next_packet_size = used * qemu_target_page_size(); - multifd_send_fill_packet(p); - p->flags = 0; - p->num_packets++; - p->num_pages += used; - p->pages->used = 0; - p->pages->block = NULL; + multifd_send_fill_packet(p, used); qemu_mutex_unlock(&p->mutex); trace_multifd_send(p->id, packet_num, used, flags, From patchwork Sat Oct 26 00:45:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 1184529 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 470Mk202mpz9sPK for ; Sat, 26 Oct 2019 11:46:34 +1100 (AEDT) Received: from localhost ([::1]:37614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOADv-0002dG-A3 for incoming@patchwork.ozlabs.org; Fri, 25 Oct 2019 20:46:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54975) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOADB-0002aS-SJ for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iOADA-0004kv-Ra for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:45 -0400 Received: from mga01.intel.com ([192.55.52.88]:5552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iOADA-0004k9-Jt for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:44 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2019 17:45:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,230,1569308400"; d="scan'208";a="204705109" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by FMSMGA003.fm.intel.com with ESMTP; 25 Oct 2019 17:45:43 -0700 From: Wei Yang To: quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v2 2/6] migration/multifd: notify channels_ready when send thread starts Date: Sat, 26 Oct 2019 08:45:16 +0800 Message-Id: <20191026004520.5515-3-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191026004520.5515-1-richardw.yang@linux.intel.com> References: <20191026004520.5515-1-richardw.yang@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Wei Yang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" multifd_send_state->channels_ready is initialized to 0. It is proper to let main thread know we are ready when thread start running. Current implementation works since ram_save_setup() calls multifd_send_sync_main() which wake up send thread and posts channels_ready. This behavior will introduce some unpredictable situation and disturb the semaphore value. This is a preparation patch to use another mechanism to do send thread synchronization to avoid post channels_ready in this case. So this patch posts channels_ready when send threads start running. Signed-off-by: Wei Yang --- migration/ram.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 35f147388b..25d477796e 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1107,6 +1107,8 @@ static void *multifd_send_thread(void *opaque) } /* initial packet */ p->num_packets = 1; + /* let main thread know we are ready */ + qemu_sem_post(&multifd_send_state->channels_ready); while (true) { qemu_sem_wait(&p->sem); From patchwork Sat Oct 26 00:45:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 1184530 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 470Mk74tWyz9sPK for ; Sat, 26 Oct 2019 11:46:39 +1100 (AEDT) Received: from localhost ([::1]:37616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOAE0-0002im-On for incoming@patchwork.ozlabs.org; Fri, 25 Oct 2019 20:46:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54994) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOADD-0002cd-BN for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iOADC-0004lS-7D for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:47 -0400 Received: from mga01.intel.com ([192.55.52.88]:5552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iOADB-0004k9-WE for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:46 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2019 17:45:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,230,1569308400"; d="scan'208";a="204705111" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by FMSMGA003.fm.intel.com with ESMTP; 25 Oct 2019 17:45:44 -0700 From: Wei Yang To: quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v2 3/6] migration/multifd: use sync field to synchronize send threads Date: Sat, 26 Oct 2019 08:45:17 +0800 Message-Id: <20191026004520.5515-4-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191026004520.5515-1-richardw.yang@linux.intel.com> References: <20191026004520.5515-1-richardw.yang@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Wei Yang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 25d477796e..62072b7a35 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -641,6 +641,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 */ @@ -1074,8 +1076,7 @@ static void multifd_send_sync_main(RAMState *rs) } p->packet_num = multifd_send_state->packet_num++; - p->flags |= MULTIFD_FLAG_SYNC; - p->pending_job++; + p->sync = true; qemu_file_update_transfer(rs->f, p->packet_len); ram_counters.multifd_bytes += p->packet_len; ram_counters.transferred += p->packet_len; @@ -1143,10 +1144,27 @@ static void *multifd_send_thread(void *opaque) p->pending_job--; qemu_mutex_unlock(&p->mutex); - if (flags & MULTIFD_FLAG_SYNC) { - qemu_sem_post(&p->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, 0); + 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(&p->sem_sync); } else if (p->quit) { qemu_mutex_unlock(&p->mutex); break; @@ -1221,7 +1239,7 @@ int multifd_save_setup(void) qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); qemu_sem_init(&p->sem_sync, 0); - p->quit = false; + p->quit = p->sync = false; p->pending_job = 0; p->id = i; p->pages = multifd_pages_init(page_count); From patchwork Sat Oct 26 00:45:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 1184536 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 470Ndv2qcRz9sPV for ; Sat, 26 Oct 2019 12:28:03 +1100 (AEDT) Received: from localhost ([::1]:37832 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOAs5-0005lA-7y for incoming@patchwork.ozlabs.org; Fri, 25 Oct 2019 21:28:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55005) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOADF-0002ez-0C for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iOADD-0004m0-J6 for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:48 -0400 Received: from mga01.intel.com ([192.55.52.88]:5552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iOADD-0004k9-BW for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:47 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2019 17:45:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,230,1569308400"; d="scan'208";a="204705113" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by FMSMGA003.fm.intel.com with ESMTP; 25 Oct 2019 17:45:46 -0700 From: Wei Yang To: quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v2 4/6] migration/multifd: used must not be 0 for a pending job Date: Sat, 26 Oct 2019 08:45:18 +0800 Message-Id: <20191026004520.5515-5-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191026004520.5515-1-richardw.yang@linux.intel.com> References: <20191026004520.5515-1-richardw.yang@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Wei Yang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" After thread synchronization request is handled in another case, this means when we only get pending_job when there is used pages. Signed-off-by: Wei Yang --- migration/ram.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 62072b7a35..12c270e86d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1132,12 +1132,11 @@ static void *multifd_send_thread(void *opaque) break; } - if (used) { - ret = qio_channel_writev_all(p->c, p->pages->iov, - used, &local_err); - if (ret != 0) { - break; - } + assert(used); + ret = qio_channel_writev_all(p->c, p->pages->iov, + used, &local_err); + if (ret != 0) { + break; } qemu_mutex_lock(&p->mutex); From patchwork Sat Oct 26 00:45:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 1184532 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 470MnS19Tvz9sPK for ; Sat, 26 Oct 2019 11:49:32 +1100 (AEDT) Received: from localhost ([::1]:37638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOAGn-0007vH-N6 for incoming@patchwork.ozlabs.org; Fri, 25 Oct 2019 20:49:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55016) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOADG-0002hU-06 for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iOADE-0004mN-Vy for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:49 -0400 Received: from mga01.intel.com ([192.55.52.88]:5552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iOADE-0004k9-NS for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:48 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2019 17:45:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,230,1569308400"; d="scan'208";a="204705117" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by FMSMGA003.fm.intel.com with ESMTP; 25 Oct 2019 17:45:47 -0700 From: Wei Yang To: quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v2 5/6] migration/multifd: use boolean for pending_job is enough Date: Sat, 26 Oct 2019 08:45:19 +0800 Message-Id: <20191026004520.5515-6-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191026004520.5515-1-richardw.yang@linux.intel.com> References: <20191026004520.5515-1-richardw.yang@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Wei Yang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" After synchronization request is handled in another case, there only could be one pending_job for one send thread at most. This is fine to use boolean to represent this behavior. Signed-off-by: Wei Yang --- migration/ram.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 12c270e86d..fccdbfabc5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -646,7 +646,7 @@ typedef struct { /* should this thread finish */ bool quit; /* thread has work to do */ - int pending_job; + bool pending_job; /* array of pages to sent */ MultiFDPages_t *pages; /* packet allocated len */ @@ -933,7 +933,7 @@ static int multifd_send_pages(RAMState *rs) return -1; } if (!p->pending_job) { - p->pending_job++; + p->pending_job = true; next_channel = (i + 1) % migrate_multifd_channels(); break; } @@ -1140,7 +1140,7 @@ static void *multifd_send_thread(void *opaque) } qemu_mutex_lock(&p->mutex); - p->pending_job--; + p->pending_job = false; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&multifd_send_state->channels_ready); @@ -1238,8 +1238,7 @@ int multifd_save_setup(void) qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem, 0); qemu_sem_init(&p->sem_sync, 0); - p->quit = p->sync = false; - p->pending_job = 0; + p->quit = p->sync = p->pending_job = false; p->id = i; p->pages = multifd_pages_init(page_count); p->packet_len = sizeof(MultiFDPacket_t) From patchwork Sat Oct 26 00:45:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 1184533 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.intel.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 470Mqn5cy3z9sPK for ; Sat, 26 Oct 2019 11:51:33 +1100 (AEDT) Received: from localhost ([::1]:37652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOAIl-0004MT-Ht for incoming@patchwork.ozlabs.org; Fri, 25 Oct 2019 20:51:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55030) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOADJ-0002pe-VD for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iOADI-0004nf-PA for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:53 -0400 Received: from mga01.intel.com ([192.55.52.88]:5552) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iOADI-0004k9-Hz for qemu-devel@nongnu.org; Fri, 25 Oct 2019 20:45:52 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2019 17:45:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,230,1569308400"; d="scan'208";a="204705119" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by FMSMGA003.fm.intel.com with ESMTP; 25 Oct 2019 17:45:49 -0700 From: Wei Yang To: quintela@redhat.com, dgilbert@redhat.com Subject: [PATCH v2 6/6] migration/multifd: there is no spurious wakeup now Date: Sat, 26 Oct 2019 08:45:20 +0800 Message-Id: <20191026004520.5515-7-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191026004520.5515-1-richardw.yang@linux.intel.com> References: <20191026004520.5515-1-richardw.yang@linux.intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Wei Yang Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The spurious wakeup is gone. Signed-off-by: Wei Yang --- migration/ram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index fccdbfabc5..73ace40b1b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1168,8 +1168,8 @@ static void *multifd_send_thread(void *opaque) qemu_mutex_unlock(&p->mutex); break; } else { - qemu_mutex_unlock(&p->mutex); - /* sometimes there are spurious wakeups */ + /* no other case should trigger me */ + g_assert_not_reached(); } }