From nobody Mon Nov 25 03:41:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1718918585; cv=none; d=zohomail.com; s=zohoarc; b=JoTWKne9lmSL9ut5HrOHEVIQUuSP7YIwDEL4WdkLcc2DkfQhUAmzNmaRR2w5UeTtrUkMZjfImEleJZ2Xyn1xkaD2KeTchXGGjjbmZSbxieXnOE5L6be6wQBnuwwmW7vM1YHlwEj7BhOX6fLhE9H66eePgY6hPxOVbN7tnQunWrc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1718918585; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HuycVr/TfjIEk380XWBsQQ+Xkk+SaTBl4KTPwhXsgAI=; b=U8YCE+ahbUzWcViWDxR7rVXtRAdhqr4apqSSlyaiMbsf6u+xju6g+NOX0+msGWfO1Cn3kXQOYChADs+a19Fdb4qnNKjka5uT7UvtQIzNwkESGZNxb8kJk2F4Ef8yVmT41Ej+0tFbV+noMYJXZBZ7/fyfA8wOeoycVmLwGDQPDAY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 171891858554459.077511153328146; Thu, 20 Jun 2024 14:23:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sKPDn-0000uH-Aw; Thu, 20 Jun 2024 17:21:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sKPDl-0000ti-DP for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:29 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sKPDj-0007GX-PJ for qemu-devel@nongnu.org; Thu, 20 Jun 2024 17:21:29 -0400 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 75B3B1F8B6; Thu, 20 Jun 2024 21:21:26 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4DD0A1369F; Thu, 20 Jun 2024 21:21:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id iGZmBVWddGabYAAAD6G6ig (envelope-from ); Thu, 20 Jun 2024 21:21:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918486; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HuycVr/TfjIEk380XWBsQQ+Xkk+SaTBl4KTPwhXsgAI=; b=FGNWovgJBiV3omDJPA/xgpP5M+zJ47SYkWQ7JMhWs69YuIGluCz7oilYjKKX7w13foxtEy OlWKnFkLpUFcJp5IIF4FsGnDao3VzjY5qfcM5FORltp7/8+aqY6Y85GazIcdP/lL9tzx5I TtmQMlb5w/W4LnK1HnrBF3i0u1t66r4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918486; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HuycVr/TfjIEk380XWBsQQ+Xkk+SaTBl4KTPwhXsgAI=; b=WEtEnsXgF9ms6/B8qRELGOJJYsajyTkuvZhKAo/askcWgDpQURxdqcbqBQ1zEa/I6jAIJH Kb2T+uwX9NyiQgBw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718918486; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HuycVr/TfjIEk380XWBsQQ+Xkk+SaTBl4KTPwhXsgAI=; b=FGNWovgJBiV3omDJPA/xgpP5M+zJ47SYkWQ7JMhWs69YuIGluCz7oilYjKKX7w13foxtEy OlWKnFkLpUFcJp5IIF4FsGnDao3VzjY5qfcM5FORltp7/8+aqY6Y85GazIcdP/lL9tzx5I TtmQMlb5w/W4LnK1HnrBF3i0u1t66r4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718918486; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HuycVr/TfjIEk380XWBsQQ+Xkk+SaTBl4KTPwhXsgAI=; b=WEtEnsXgF9ms6/B8qRELGOJJYsajyTkuvZhKAo/askcWgDpQURxdqcbqBQ1zEa/I6jAIJH Kb2T+uwX9NyiQgBw== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: Peter Xu , "Maciej S . Szmigiero" Subject: [RFC PATCH 7/7] migration/multifd: Hide multifd slots implementation Date: Thu, 20 Jun 2024 18:21:11 -0300 Message-Id: <20240620212111.29319-8-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240620212111.29319-1-farosas@suse.de> References: <20240620212111.29319-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1718918587544100003 Content-Type: text/plain; charset="utf-8" The only two things the multifd client needs to access are the active slot and the active slot size: The active slot itself is obviously needed because it's where the data is put. The slot size is needed only by the ram pages code, because it does not fill the data slot and sends it in one go, it instead fills the slot partially at each call of multifd_queue_page(), so the size is needed to differentiate an empty slot (free or recently consumed) from the slot that is partially full. Hide the MultiFDSlots implementation so the client is not tempted to make use of the free list. That field is there simply because we need the client to carry a handle to that memory, it's not supposed to be accessed directly. Signed-off-by: Fabiano Rosas --- migration/multifd.c | 26 +++++++++++++++++++++++--- migration/multifd.h | 8 +++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index f22a1c2e84..9fb719eb0d 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -38,6 +38,11 @@ #define MULTIFD_MAGIC 0x11223344U #define MULTIFD_VERSION 1 =20 +struct MultiFDSlots { + MultiFDSendData **free; + MultiFDSendData *active; +}; + typedef struct { uint32_t magic; uint32_t version; @@ -737,7 +742,22 @@ static inline bool multifd_queue_full(MultiFDPages_t *= pages) static inline void multifd_enqueue(MultiFDPages_t *pages, ram_addr_t offse= t) { pages->offset[pages->num++] =3D offset; - multifd_ram_send_slots->active->size +=3D qemu_target_page_size(); + multifd_set_slot_size(multifd_ram_send_slots, qemu_target_page_size()); +} + +void *multifd_get_active_slot(MultiFDSlots *multifd_ram_send_slots) +{ + return multifd_ram_send_slots->active->opaque; +} + +void multifd_set_slot_size(MultiFDSlots *multifd_ram_send_slots, size_t si= ze) +{ + multifd_ram_send_slots->active->size +=3D size; +} + +bool multifd_slot_has_data(MultiFDSlots *multifd_ram_send_slots) +{ + return !!multifd_ram_send_slots->active->size; } =20 /* Returns true if enqueue successful, false otherwise */ @@ -746,7 +766,7 @@ bool multifd_queue_page(RAMBlock *block, ram_addr_t off= set) MultiFDPages_t *pages; =20 retry: - pages =3D multifd_ram_send_slots->active->opaque; + pages =3D multifd_get_active_slot(multifd_ram_send_slots); =20 /* If the queue is empty, we can already enqueue now */ if (multifd_queue_empty(pages)) { @@ -951,7 +971,7 @@ int multifd_send_sync_main(void) return 0; } =20 - if (multifd_ram_send_slots->active->size) { + if (multifd_slot_has_data(multifd_ram_send_slots)) { if (!multifd_send(multifd_ram_send_slots)) { error_report("%s: multifd_send_pages fail", __func__); return -1; diff --git a/migration/multifd.h b/migration/multifd.h index 5230729077..8f99fe2652 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -102,15 +102,13 @@ struct MultiFDSendData { void (*cleanup)(void *); }; =20 -struct MultiFDSlots { - MultiFDSendData **free; - MultiFDSendData *active; -}; - MultiFDSlots *multifd_allocate_slots(void *(*alloc_fn)(void), void (*reset_fn)(void *), void (*cleanup_fn)(void *)); void multifd_ram_save_setup(void); +void *multifd_get_active_slot(MultiFDSlots *multifd_ram_send_slots); +void multifd_set_slot_size(MultiFDSlots *multifd_ram_send_slots, size_t si= ze); +bool multifd_slot_has_data(MultiFDSlots *multifd_ram_send_slots); =20 typedef struct { /* Fields are only written at creating/deletion time */ --=20 2.35.3