From nobody Mon Feb 9 23:57:48 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565748380; cv=none; d=zoho.com; s=zohoarc; b=MX6bgmKICS5cHgNChtVsEkJLwlWCUEKF3j2YTqi+njvgIEwtjxXAsrXWCMAXg9KHNDEfCX6lwEw59t13m/g8ZXHsgm5hytzlFHGtZ+xu7WfZF2P7uI0w07xABrFLmW15ceBBIvaR33iZG8TP4buYXXTUkd8uyRMy+px4yP2AEc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565748380; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=QvulvnFuoxKV/VZLhIbGZ+9i8pYFICsSIzp3CpTQ89s=; b=TYsty6v6PhqjJ+Dg/amyJTc4HLXp46HWYlgpQUrcK3Qp0aMGWcUPXnrfYzSxdl8cIDm4q+jPVlWVS3MEdWshr2A5Jiu3Wt52Q+Tg7RErSQanvoevBzsMFyi9CwE2TweIryp0ybCm8AglmO8H4c5DXH5/bJn71fIsSMvZhijLDSI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1565748380641361.2655659621912; Tue, 13 Aug 2019 19:06:20 -0700 (PDT) Received: from localhost ([::1]:56614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hxig7-0005Ya-5X for importer@patchew.org; Tue, 13 Aug 2019 22:06:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51008) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hxicV-0001K0-Nw for qemu-devel@nongnu.org; Tue, 13 Aug 2019 22:02:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hxicU-0005J3-ML for qemu-devel@nongnu.org; Tue, 13 Aug 2019 22:02:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54430) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hxicU-0005Id-Ec for qemu-devel@nongnu.org; Tue, 13 Aug 2019 22:02:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BF9ED3082E0F for ; Wed, 14 Aug 2019 02:02:33 +0000 (UTC) Received: from localhost.localdomain (ovpn-117-78.ams2.redhat.com [10.36.117.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 188FD7AB44; Wed, 14 Aug 2019 02:02:30 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 14 Aug 2019 04:02:16 +0200 Message-Id: <20190814020218.1868-5-quintela@redhat.com> In-Reply-To: <20190814020218.1868-1-quintela@redhat.com> References: <20190814020218.1868-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 14 Aug 2019 02:02:33 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 4/6] migration: Make multifd threads wait until all have been created 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: "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This makes it clear that no thread handles any incoming message until all threads have been created. Signed-off-by: Juan Quintela --- migration/ram.c | 24 ++++++++++++++++++++++-- migration/trace-events | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 4a6ae677a9..f1aec95f83 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -702,6 +702,8 @@ typedef struct { uint64_t num_pages; /* syncs main thread and channels */ QemuSemaphore sem_sync; + /* thread can continue */ + QemuSemaphore can_start; } MultiFDRecvParams; =20 static int multifd_send_initial_packet(MultiFDSendParams *p, Error **errp) @@ -1313,6 +1315,7 @@ int multifd_load_cleanup(Error **errp) p->c =3D NULL; qemu_mutex_destroy(&p->mutex); qemu_sem_destroy(&p->sem_sync); + qemu_sem_destroy(&p->can_start); g_free(p->name); p->name =3D NULL; multifd_pages_clear(p->pages); @@ -1366,6 +1369,9 @@ static void *multifd_recv_thread(void *opaque) trace_multifd_recv_thread_start(p->id); rcu_register_thread(); =20 + qemu_sem_wait(&p->can_start); + trace_multifd_recv_thread_can_start(p->id); + while (true) { uint32_t used; uint32_t flags; @@ -1445,6 +1451,7 @@ int multifd_load_setup(void) =20 qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem_sync, 0); + qemu_sem_init(&p->can_start, 0); p->quit =3D false; p->id =3D i; p->pages =3D multifd_pages_init(page_count); @@ -1477,6 +1484,7 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) { MultiFDRecvParams *p; Error *local_err =3D NULL; + bool last_one; int id; =20 id =3D multifd_recv_initial_packet(ioc, &local_err); @@ -1506,8 +1514,20 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error= **errp) qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, QEMU_THREAD_JOINABLE); atomic_inc(&multifd_recv_state->count); - return atomic_read(&multifd_recv_state->count) =3D=3D - migrate_multifd_channels(); + + last_one =3D atomic_read(&multifd_recv_state->count) + =3D=3D migrate_multifd_channels(); + + if (last_one) { + int i; + + for (i =3D 0; i < migrate_multifd_channels(); i++) { + MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; + + qemu_sem_post(&p->can_start); + } + } + return last_one; } =20 /** diff --git a/migration/trace-events b/migration/trace-events index dd13a5c4b1..9fbef614ab 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -86,6 +86,7 @@ multifd_recv_sync_main(long packet_num) "packet num %ld" multifd_recv_sync_main_signal(uint8_t id) "channel %d" multifd_recv_sync_main_wait(uint8_t id) "channel %d" multifd_recv_terminate_threads(bool error) "error %d" +multifd_recv_thread_can_start(uint8_t id) "channel %d" multifd_recv_thread_end(uint8_t id, uint64_t packets, uint64_t pages) "cha= nnel %d packets %" PRIu64 " pages %" PRIu64 multifd_recv_thread_start(uint8_t id) "%d" multifd_send(uint8_t id, uint64_t packet_num, uint32_t used, uint32_t flag= s, uint32_t next_packet_size) "channel %d packet_num %" PRIu64 " pages %d f= lags 0x%x next packet size %d" --=20 2.21.0