From nobody Mon Feb 9 18:45:20 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=samsung.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152174299974636.00712560955037; Thu, 22 Mar 2018 11:23:19 -0700 (PDT) Received: from localhost ([::1]:34171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ez4rr-0003Fc-RC for importer@patchew.org; Thu, 22 Mar 2018 14:23:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ez4mb-00079F-NF for qemu-devel@nongnu.org; Thu, 22 Mar 2018 14:17:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ez4mY-0000bZ-Il for qemu-devel@nongnu.org; Thu, 22 Mar 2018 14:17:49 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:44920) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ez4mY-0000aF-3F for qemu-devel@nongnu.org; Thu, 22 Mar 2018 14:17:46 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20180322181742euoutp02f6c337919437c1846a768335b5736dc6~eUOOV--ls2880228802euoutp02K; Thu, 22 Mar 2018 18:17:42 +0000 (GMT) Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20180322181741eucas1p291ac36d7eedbc7eb642bffc329a92f55~eUONp1u8I2588325883eucas1p2f; Thu, 22 Mar 2018 18:17:41 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 84.B7.05700.543F3BA5; Thu, 22 Mar 2018 18:17:41 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20180322181740eucas1p13028d8418e837695a91ded89385f8978~eUOM2GkuI1717817178eucas1p1D; Thu, 22 Mar 2018 18:17:40 +0000 (GMT) Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 25.AC.04183.443F3BA5; Thu, 22 Mar 2018 18:17:40 +0000 (GMT) Received: from aperevalov-ubuntu.rnd.samsung.ru ([106.109.129.199]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0P60001OD857D350@eusync4.samsung.com>; Thu, 22 Mar 2018 18:17:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20180322181742euoutp02f6c337919437c1846a768335b5736dc6~eUOOV--ls2880228802euoutp02K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1521742662; bh=QAffSg1stlS//4+QG5alXTArNOLS7gEGVbS+I13mrkM=; h=From:To:Cc:Subject:Date:In-reply-to:References:From; b=Arx9dMKeWJ9U0oU8cO2ttMQE4UMY7nxqnPDO1h0mawDtNwhY22UhAl0QmdS7Fj5qP 779pc/3IK/6QY/mvca0e/zt25WGLAXeu5aLk2lLJemHkmpYmiIHOVpvRfrr7OWN3F7 TowA/D38E/PZLX2vTC8mgcpsMswF1iYqQuTh+oBo= X-AuditID: cbfec7f2-1dbff70000011644-52-5ab3f3456cf0 From: Alexey Perevalov To: qemu-devel@nongnu.org, dgilbert@redhat.com Date: Thu, 22 Mar 2018 21:17:23 +0300 Message-id: <1521742647-25550-3-git-send-email-a.perevalov@samsung.com> X-Mailer: git-send-email 2.7.4 In-reply-to: <1521742647-25550-1-git-send-email-a.perevalov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFIsWRmVeSWpSXmKPExsWy7djPc7qunzdHGexcKWkx9+55FouVk5cw WfRuu8ducWLTQWaLTw1SFlv2f2O3ON67g8XizpY+JovTNzezO3B6HHixkN3jybXNTB7v911l 8+jbsooxgCWKyyYlNSezLLVI3y6BK2PV90PMBSc1KravvcPSwHhToYuRg0NCwERi5lbnLkYu DiGBFYwS3753MUI4nxklDu4+A+RwghV9WbcLKrGMUWLB8yZmCKebSeJ4w3JmkFFsAgYS++7Z gpgiAnoSE65GgpQwC2xklNh55z0LyCBhgWiJCQtfMIHYLAKqEpdWnmcDsXkF3CW+921ngVgm J3HzXCcziM0p4CGx99YmsMUSAj1sEjOOd7NDFLlIHF7ayQphC0u8Or4FKi4jcXlyNwtEQzuj xN2NV1khnAmMEusmH2OGqLKXOHXzKtgZzAJ8EpO2TWeGBAavREebEESJh8ShjTPYIGxHiZ0/ brNAfDybUeLm6e+MExilFjAyrGIUTy0tzk1PLTbMSy3XK07MLS7NS9dLzs/dxAiM0dP/jn/a wfj1UtIhRgEORiUe3hmHNkcJsSaWFVfmHmKU4GBWEuHNXwsU4k1JrKxKLcqPLyrNSS0+xCjN waIkzhunURclJJCeWJKanZpakFoEk2Xi4JRqYHTjO/Sg65Mxk5h9lZBue3vL3JR1RlwOH4+s UXd9Vujwevq7ixLxO53maZ9IMfslJPSvmK/kpQ9rwPz0mHvy8p89X19sEo1beXKuYW3qHnaN D+73FRuKvnR6fdy+IyI74tfPYMHMjQb3Hh91kL5o8P6H7L4GpQiDJL2Q9T2hItWG8orbecy9 lViKMxINtZiLihMB2Btqk80CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmluLIzCtJLcpLzFFi42I5/e/4NV2Xz5ujDK51GljMvXuexWLl5CVM Fr3b7rFbnNh0kNniU4OUxZb939gtjvfuYLG4s6WPyeL0zc3sDpweB14sZPd4cm0zk8f7fVfZ PPq2rGIMYInisklJzcksSy3St0vgylj1/RBzwUmNiu1r77A0MN5U6GLk5JAQMJH4sm4XYxcj F4eQwBJGiaOnYJxeJokfW/6zdzFycLAJGEjsu2cLYooI6ElMuBoJUsIssJFR4teMu6wgg4QF oiUmLHzBBGKzCKhKXFp5ng3E5hVwl/jet50FYpmcxM1zncwgNqeAh8TeW5sYQWwhoJpdF64x T2DkWcDIsIpRJLW0ODc9t9hIrzgxt7g0L10vOT93EyMwiLYd+7llB2PXu+BDjAIcjEo8vDMO bY4SYk0sK67MPcQowcGsJMKbvxYoxJuSWFmVWpQfX1Sak1p8iFGag0VJnPe8QWWUkEB6Yklq dmpqQWoRTJaJg1OqgdFYaGnIjn1CfSEP3I6KcNuIySk6yFaGHGNa32twXfD7w7LFcrtMT9b3 mfdk1i6qCLi1V+OCU4FI4CzOqZcM77yzdA+f8FR/9Sp++9h9O1ne/+x48Kvxxf2bRR1PhAtk tZU8ryuI74y6v/iUgPf8iB/ydroTORaXNJ5i2SecupeV6ZTSnRPCN5RYijMSDbWYi4oTAbj2 caoeAgAA X-CMS-MailID: 20180322181740eucas1p13028d8418e837695a91ded89385f8978 X-Msg-Generator: CA CMS-TYPE: 201P X-CMS-RootMailID: 20180322181740eucas1p13028d8418e837695a91ded89385f8978 X-RootMTR: 20180322181740eucas1p13028d8418e837695a91ded89385f8978 References: <1521742647-25550-1-git-send-email-a.perevalov@samsung.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 210.118.77.12 Subject: [Qemu-devel] [PATCH v2 2/6] migration: add postcopy blocktime ctx into MigrationIncomingState 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: lvivier@redhat.com, v.kuramshin@samsung.com, quintela@redhat.com, ash.billore@samsung.com, Alexey Perevalov , peterx@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds request to kernel space for UFFD_FEATURE_THREAD_ID, in case this feature is provided by kernel. PostcopyBlocktimeContext is encapsulated inside postcopy-ram.c, due to it being a postcopy-only feature. Also it defines PostcopyBlocktimeContext's instance live time. Information from PostcopyBlocktimeContext instance will be provided much after postcopy migration end, instance of PostcopyBlocktimeContext will live till QEMU exit, but part of it (vcpu_addr, page_fault_vcpu_time) used only during calculation, will be released when postcopy ended or failed. To enable postcopy blocktime calculation on destination, need to request proper compatibility (Patch for documentation will be at the tail of the patch set). As an example following command enable that capability, assume QEMU was started with -chardev socket,id=3Dcharmonitor,path=3D/var/lib/migrate-vm-monitor.sock option to control it [root@host]#printf "{\"execute\" : \"qmp_capabilities\"}\r\n \ {\"execute\": \"migrate-set-capabilities\" , \"arguments\": { \"capabilities\": [ { \"capability\": \"postcopy-blocktime\", \"state\": true } ] } }" | nc -U /var/lib/migrate-vm-monitor.sock Or just with HMP (qemu) migrate_set_capability postcopy-blocktime on Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Alexey Perevalov Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.h | 8 +++++++ migration/postcopy-ram.c | 61 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 69 insertions(+) diff --git a/migration/migration.h b/migration/migration.h index 46a50bc..6d9aaeb 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -22,6 +22,8 @@ #include "hw/qdev.h" #include "io/channel.h" =20 +struct PostcopyBlocktimeContext; + /* State for the incoming migration */ struct MigrationIncomingState { QEMUFile *from_src_file; @@ -65,6 +67,12 @@ struct MigrationIncomingState { /* The coroutine we should enter (back) after failover */ Coroutine *migration_incoming_co; QemuSemaphore colo_incoming_sem; + + /* + * PostcopyBlocktimeContext to keep information for postcopy + * live migration, to calculate vCPU block time + * */ + struct PostcopyBlocktimeContext *blocktime_ctx; }; =20 MigrationIncomingState *migration_incoming_get_current(void); diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index efd7793..66f1df9 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -90,6 +90,54 @@ int postcopy_notify(enum PostcopyNotifyReason reason, Er= ror **errp) #include #include =20 +typedef struct PostcopyBlocktimeContext { + /* time when page fault initiated per vCPU */ + uint32_t *page_fault_vcpu_time; + /* page address per vCPU */ + uintptr_t *vcpu_addr; + uint32_t total_blocktime; + /* blocktime per vCPU */ + uint32_t *vcpu_blocktime; + /* point in time when last page fault was initiated */ + uint32_t last_begin; + /* number of vCPU are suspended */ + int smp_cpus_down; + uint64_t start_time; + + /* + * Handler for exit event, necessary for + * releasing whole blocktime_ctx + */ + Notifier exit_notifier; +} PostcopyBlocktimeContext; + +static void destroy_blocktime_context(struct PostcopyBlocktimeContext *ctx) +{ + g_free(ctx->page_fault_vcpu_time); + g_free(ctx->vcpu_addr); + g_free(ctx->vcpu_blocktime); + g_free(ctx); +} + +static void migration_exit_cb(Notifier *n, void *data) +{ + PostcopyBlocktimeContext *ctx =3D container_of(n, PostcopyBlocktimeCon= text, + exit_notifier); + destroy_blocktime_context(ctx); +} + +static struct PostcopyBlocktimeContext *blocktime_context_new(void) +{ + PostcopyBlocktimeContext *ctx =3D g_new0(PostcopyBlocktimeContext, 1); + ctx->page_fault_vcpu_time =3D g_new0(uint32_t, smp_cpus); + ctx->vcpu_addr =3D g_new0(uintptr_t, smp_cpus); + ctx->vcpu_blocktime =3D g_new0(uint32_t, smp_cpus); + + ctx->exit_notifier.notify =3D migration_exit_cb; + ctx->start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + qemu_add_exit_notifier(&ctx->exit_notifier); + return ctx; +} =20 /** * receive_ufd_features: check userfault fd features, to request only supp= orted @@ -182,6 +230,19 @@ static bool ufd_check_and_apply(int ufd, MigrationInco= mingState *mis) } } =20 +#ifdef UFFD_FEATURE_THREAD_ID + if (migrate_postcopy_blocktime() && mis && + UFFD_FEATURE_THREAD_ID & supported_features) { + /* kernel supports that feature */ + /* don't create blocktime_context if it exists */ + if (!mis->blocktime_ctx) { + mis->blocktime_ctx =3D blocktime_context_new(); + } + + asked_features |=3D UFFD_FEATURE_THREAD_ID; + } +#endif + /* * request features, even if asked_features is 0, due to * kernel expects UFFD_API before UFFDIO_REGISTER, per --=20 2.7.4