From patchwork Wed Apr 26 05:06:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Perevalov X-Patchwork-Id: 9700289 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 274B86032C for ; Wed, 26 Apr 2017 05:11:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 137DB284DB for ; Wed, 26 Apr 2017 05:11:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0546C2857F; Wed, 26 Apr 2017 05:11:53 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 778BB284DB for ; Wed, 26 Apr 2017 05:11:52 +0000 (UTC) Received: from localhost ([::1]:52662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3FF1-0005OT-QF for patchwork-qemu-devel@patchwork.kernel.org; Wed, 26 Apr 2017 01:11:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60665) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d3FA2-0001xV-J3 for qemu-devel@nongnu.org; Wed, 26 Apr 2017 01:06:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d3F9x-0002uA-Oh for qemu-devel@nongnu.org; Wed, 26 Apr 2017 01:06:42 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:32442) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d3F9x-0002tk-Ih for qemu-devel@nongnu.org; Wed, 26 Apr 2017 01:06:37 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OP000A5S3IZEN00@mailout3.w1.samsung.com> for qemu-devel@nongnu.org; Wed, 26 Apr 2017 06:06:35 +0100 (BST) Received: from eusmges4.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20170426050635eucas1p2ca17145986dfb14acd12ff97c35d1db5~42jRnPDMF0498304983eucas1p2P; Wed, 26 Apr 2017 05:06:35 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges4.samsung.com (EUCPMTA) with SMTP id 36.F1.04729.ADA20095; Wed, 26 Apr 2017 06:06:34 +0100 (BST) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170426050634eucas1p1a1c95d312025c99453a185084b75396a~42jQ8GFAE2511225112eucas1p1H; Wed, 26 Apr 2017 05:06:34 +0000 (GMT) X-AuditID: cbfec7f4-f79806d000001279-f1-59002ada9cd4 Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 6A.E5.17452.06B20095; Wed, 26 Apr 2017 06:08:48 +0100 (BST) Received: from aperevalov-ubuntu.rnd.samsung.ru ([106.109.129.199]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OP000MTF3IPGF20@eusync1.samsung.com>; Wed, 26 Apr 2017 06:06:34 +0100 (BST) From: Alexey Perevalov To: dgilbert@redhat.com Date: Wed, 26 Apr 2017 08:06:18 +0300 Message-id: <1493183181-21962-5-git-send-email-a.perevalov@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1493183181-21962-1-git-send-email-a.perevalov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrPIsWRmVeSWpSXmKPExsWy7djPc7q3tBgiDXa8NbSYe/c8i0Xvtnvs Fic2HWS2uNL+k91iy/5v7BbHe3ewOLB5HHixkN3jybXNTB7v911l8+jbsooxgCWKyyYlNSez LLVI3y6BK2PKhm62gn9yFYemPmdpYHwr0cXIwSEhYCLxZKJrFyMnkCkmceHeerYuRi4OIYGl jBKPPt9nhHA+M0pc6rrOClFlIvF2zn4WiMQyRomT3zqgnG4miVlr9rOBjGUTMJDYd88WpEFE QFzi3b4GdhCbWaBAYuenHWwgtrBAuMScpz/A4iwCqhLnluwGs3kF3CXWH9nCDrFMTuLksclg izkFPCTWr3/DDBF/ziax9Zo6xAeyEpsOQIVdJLp+/oe6U1ji1XGYMTISnR0HmUDOlBBoZ5To 3tnJCuFMYJQ4M/0vVJW9xKmbV5kgDuWTmLRtOjPEAl6JjjYhiBIPid3db5kgbEeJBV9Ws0P8 PptR4svtSewTGGUWMDKsYhRJLS3OTU8tNtErTswtLs1L10vOz93ECIzW0/+Of9nBuPiY1SFG AQ5GJR7eFV7/I4RYE8uKK3MPMUpwMCuJ8IZrMEQK8aYkVlalFuXHF5XmpBYfYpTmYFES5+U6 dS1CSCA9sSQ1OzW1ILUIJsvEwSnVwLjq3qxgY/Vj83aZ1kVVlAm2+jPeXDVhlnWKs2iDdvR3 K+1Zl4pbI+5tvNo/4ftkhaeV4r8v6MjrNu3ftfbe7svTeH7mntzYtVG77u/byaIt93cxnIo8 7az+/Zrq9M9bHD7/nP36juKO5V3q69s0eZUs3upIr11k6xwfPjvz9aRVn7gW2Pv38G5SYinO SDTUYi4qTgQAipEXUtICAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrPLMWRmVeSWpSXmKPExsVy+t/xy7oJ2gyRBlde2FjMvXuexaJ32z12 ixObDjJbXGn/yW6xZf83dovjvTtYHNg8DrxYyO7x5NpmJo/3+66yefRtWcUYwBLlZpORmpiS WqSQmpecn5KZl26rFBripmuhpJCXmJtqqxSh6xsSpKRQlphTCuQZGaABB+cA92AlfbsEt4wp G7rZCv7JVRya+pylgfGtRBcjJ4eEgInE2zn7WSBsMYkL99azdTFycQgJLGGUmNzZyQrh9DJJ rDuznrmLkYODTcBAYt89W5AGEQFxiXf7GthBbGaBAomzi/czgtjCAuESc57+AIuzCKhKnFuy G8zmFXCXWH9kCzvEMjmJk8cms4LYnAIeEuvXv2EGsYWAauZcXcY6gZF3ASPDKkaR1NLi3PTc YkO94sTc4tK8dL3k/NxNjMDA3Xbs5+YdjJc2Bh9iFOBgVOLhDfD4HyHEmlhWXJl7iFGCg1lJ hDdcgyFSiDclsbIqtSg/vqg0J7X4EKMp0FETmaVEk/OBUZVXEm9oYmhuaWhkbGFhbmSkJM5b 8uFKuJBAemJJanZqakFqEUwfEwenVAPjHHntWI2Nvyy2ZWcs6Z8b3jexaYuM1MXELbUfDQ5c yVR29DMrWJuxaZV50+98QTcJn5o7ra/TltdPvPdwnkUQRzNP/VRl3fV/j5v6BT5OVzBmK5WZ VcbF9vD+pGXMhZ/4Zu7T91IwrnKfF/E0jEH8W/6MjG85fusbnzmGrTJc29O3jpfb4qkSS3FG oqEWc1FxIgC9i7FicgIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170426050634eucas1p1a1c95d312025c99453a185084b75396a X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?QWxleGV5IFBlcmV2YWxvdhtTUlItVmlydHVhbGl6YXRpb24g?= =?UTF-8?B?TGFiG+yCvOyEseyghOyekBtTZW5pb3IgRW5naW5lZXI=?= X-Global-Sender: =?UTF-8?B?QWxleGV5IFBlcmV2YWxvdhtTUlItVmlydHVhbGl6YXRpb24g?= =?UTF-8?B?TGFiG1NhbXN1bmcgRWxlY3Ryb25pY3MbU2VuaW9yIEVuZ2luZWVy?= X-Sender-Code: =?UTF-8?B?QzEwG0NJU0hRG0MxMEdEMDFHRDAxMDE1NA==?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170426050634eucas1p1a1c95d312025c99453a185084b75396a X-RootMTR: 20170426050634eucas1p1a1c95d312025c99453a185084b75396a References: <1493183181-21962-1-git-send-email-a.perevalov@samsung.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 210.118.77.13 Subject: [Qemu-devel] [PATCH V3 4/6] migration: add postcopy downtime into MigrationIncommingState 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: i.maximets@samsung.com, qemu-devel@nongnu.org, a.perevalov@samsung.com, peterx@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch add request to kernel space for UFFD_FEATURE_THREAD_ID, in case when this feature is provided by kernel. DowntimeContext is incapsulated inside migration.c. Signed-off-by: Alexey Perevalov --- include/migration/migration.h | 12 ++++++++++++ migration/migration.c | 33 +++++++++++++++++++++++++++++++++ migration/postcopy-ram.c | 8 ++++++++ 3 files changed, 53 insertions(+) diff --git a/include/migration/migration.h b/include/migration/migration.h index 5720c88..b1759f7 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -83,6 +83,8 @@ typedef enum { POSTCOPY_INCOMING_END } PostcopyState; +struct DowntimeContext; + /* State for the incoming migration */ struct MigrationIncomingState { QEMUFile *from_src_file; @@ -123,10 +125,20 @@ struct MigrationIncomingState { /* See savevm.c */ LoadStateEntry_Head loadvm_handlers; + + /* + * DowntimeContext to keep information for postcopy + * live migration, to calculate downtime + * */ + struct DowntimeContext *downtime_ctx; }; MigrationIncomingState *migration_incoming_get_current(void); void migration_incoming_state_destroy(void); +/* + * Functions to work with downtime context + */ +struct DowntimeContext *downtime_context_new(void); /* * An outstanding page request, on the source, having been received diff --git a/migration/migration.c b/migration/migration.c index 79f6425..0309c2b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -77,6 +77,18 @@ static NotifierList migration_state_notifiers = static bool deferred_incoming; +typedef struct DowntimeContext { + /* time when page fault initiated per vCPU */ + int64_t *page_fault_vcpu_time; + /* page address per vCPU */ + uint64_t *vcpu_addr; + int64_t total_downtime; + /* downtime per vCPU */ + int64_t *vcpu_downtime; + /* point in time when last page fault was initiated */ + int64_t last_begin; +} DowntimeContext; + /* * Current state of incoming postcopy; note this is not part of * MigrationIncomingState since it's state is used during cleanup @@ -117,6 +129,23 @@ MigrationState *migrate_get_current(void) return ¤t_migration; } +struct DowntimeContext *downtime_context_new(void) +{ + DowntimeContext *ctx = g_new0(DowntimeContext, 1); + ctx->page_fault_vcpu_time = g_new0(int64_t, smp_cpus); + ctx->vcpu_addr = g_new0(uint64_t, smp_cpus); + ctx->vcpu_downtime = g_new0(int64_t, smp_cpus); + return ctx; +} + +static void destroy_downtime_context(struct DowntimeContext *ctx) +{ + g_free(ctx->page_fault_vcpu_time); + g_free(ctx->vcpu_addr); + g_free(ctx->vcpu_downtime); + g_free(ctx); +} + MigrationIncomingState *migration_incoming_get_current(void) { static bool once; @@ -139,6 +168,10 @@ void migration_incoming_state_destroy(void) qemu_event_destroy(&mis->main_thread_load_event); loadvm_free_handlers(mis); + if (mis->downtime_ctx) { + destroy_downtime_context(mis->downtime_ctx); + mis->downtime_ctx = NULL; + } } diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 55b5243..ce1ea5d 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -132,6 +132,14 @@ static bool ufd_version_check(int ufd, MigrationIncomingState *mis) return false; } +#ifdef UFFD_FEATURE_THREAD_ID + if (mis && UFFD_FEATURE_THREAD_ID & supported_features) { + /* kernel supports that feature */ + mis->downtime_ctx = downtime_context_new(); + new_features |= UFFD_FEATURE_THREAD_ID; + } +#endif + /* request features */ if (new_features && !request_ufd_features(ufd, new_features)) { error_report("ufd_version_check failed: features %" PRIu64,