From patchwork Fri Oct 20 15:23:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13430876 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 45D2EC00A98 for ; Fri, 20 Oct 2023 15:27:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtrO8-0002qj-IE; Fri, 20 Oct 2023 11:26:12 -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 1qtrO4-0002gw-Tz for qemu-devel@nongnu.org; Fri, 20 Oct 2023 11:26:08 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtrO1-00060c-S5 for qemu-devel@nongnu.org; Fri, 20 Oct 2023 11:26:08 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1ca74e77aecso15647035ad.1 for ; Fri, 20 Oct 2023 08:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1697815443; x=1698420243; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IQwXPhv+suUODSVaOFT/uvjWZ0giK1V2oP5SwGbONBE=; b=RqJP9v+772MdWdjHpO4nozJWSE9vQ5J+xhrNy4ptLNqHjDY0hj0/2Z0YCDut2Xv1AJ aB/pw7Wz2w23WZq3C9GFdncRiOZQowaAt1B1H13MNxitoNM3FOKsvoZQ0h/ciwrNDGRS 9/9LWdZZhg3koKIceYZ7CH5Ti+D6kZZUX08AurjYlit+ze0oNCOLspEQTc1tywvmTCdy uyZBvtB9EeW3CwAXcnoSrm39GBfvHZLzEy4ITQNWv21aJPIFv/q+oFE7XzxqA5Rm7t0A aEkwrmNkwnHOu5RY6RTgvcU2Sy+IelDLat5y++jCiVzvcl5oP0nsbMwQ5FsjtVT4yfyO cYug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697815443; x=1698420243; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IQwXPhv+suUODSVaOFT/uvjWZ0giK1V2oP5SwGbONBE=; b=DRfxeYvJDj+Yx9RHBuBqDalBC3EVGC9cICmoExUrxNmrmL2qEiNk/UiCsvkdoAiNbQ mqCZcBvKQY6970NIxIrvuGp87BhdnGXqbWIZT4FGoM1Eiu6WHXIZUo8b7pBazaGdvLGZ Dx/GmDbrngJBTEMf9bBNsg1nAHaR43AgL9agMbqADnHq4JUvnjPzkateTx+JlqM2AufJ I7vSxMjMgjFdnE8fECJrOhiPLhnVTnCEe0/vCPQzck+TMpL9KVP7sW91QCcleIrxs/CE 4BS3rFgwqmRGbXsIR2U3Hg3WX1Ok47FGpkVkKH4AvaoOLYMewcmIInZTu48bF6JOsnOV oQfA== X-Gm-Message-State: AOJu0Yxk9bgXGpR2IFSkaagUWhK3dKvhFP6cxp771Xr6c20Napwv5lt7 ElX3szUnFimyfOLu+dPPD3npIycTpL5Pt5EsroyPcE4V X-Google-Smtp-Source: AGHT+IHombyZ6D0T+fsB2qGSszQFtb8Ux1CIfsamDAyWx1cmZqAeFOuQ9q1d5NshrXxkcxOjAnD8/g== X-Received: by 2002:a17:903:1c3:b0:1c7:22ae:4080 with SMTP id e3-20020a17090301c300b001c722ae4080mr2878261plh.0.1697815443264; Fri, 20 Oct 2023 08:24:03 -0700 (PDT) Received: from localhost.localdomain ([171.216.79.181]) by smtp.gmail.com with ESMTPSA id d4-20020a170902cec400b001c60d0a6d84sm1644824plg.127.2023.10.20.08.24.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 08:24:03 -0700 (PDT) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Juan Quintela , Peter Xu , Fabiano Rosas , Leonardo Bras , Thomas Huth , Laurent Vivier , Paolo Bonzini , Hyman Huang Subject: [v2 1/6] system/dirtylimit: Fix a race situation Date: Fri, 20 Oct 2023 23:23:43 +0800 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::62b; envelope-from=yong.huang@smartx.com; helo=mail-pl1-x62b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Fix a race situation for global variable dirtylimit_state. Also, replace usleep by g_usleep to increase platform accessibility to the sleep function. Signed-off-by: Hyman Huang Reviewed-by: Fabiano Rosas --- system/dirtylimit.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/system/dirtylimit.c b/system/dirtylimit.c index fa959d7743..3666c4cb7c 100644 --- a/system/dirtylimit.c +++ b/system/dirtylimit.c @@ -411,12 +411,20 @@ void dirtylimit_set_all(uint64_t quota, void dirtylimit_vcpu_execute(CPUState *cpu) { - if (dirtylimit_in_service() && - dirtylimit_vcpu_get_state(cpu->cpu_index)->enabled && - cpu->throttle_us_per_full) { - trace_dirtylimit_vcpu_execute(cpu->cpu_index, - cpu->throttle_us_per_full); - usleep(cpu->throttle_us_per_full); + if (cpu->throttle_us_per_full) { + dirtylimit_state_lock(); + + if (dirtylimit_in_service() && + dirtylimit_vcpu_get_state(cpu->cpu_index)->enabled) { + dirtylimit_state_unlock(); + trace_dirtylimit_vcpu_execute(cpu->cpu_index, + cpu->throttle_us_per_full); + + g_usleep(cpu->throttle_us_per_full); + return; + } + + dirtylimit_state_unlock(); } } From patchwork Fri Oct 20 15:23:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13430874 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 4351CC0032E for ; Fri, 20 Oct 2023 15:27:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtrO9-0002uW-4S; Fri, 20 Oct 2023 11:26:13 -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 1qtrO6-0002nm-Ky for qemu-devel@nongnu.org; Fri, 20 Oct 2023 11:26:10 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtrO4-00063m-AS for qemu-devel@nongnu.org; Fri, 20 Oct 2023 11:26:10 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1caad0bcc95so6814805ad.0 for ; Fri, 20 Oct 2023 08:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1697815447; x=1698420247; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AkQEX6C2wW1mPOWLXApStdvqFKYQwdr8AV6yMr5GZQk=; b=KI+LiRBx41aMUKZvcMDkCisDhu98FMG8KQmHuLkmTNVBK/jLQ6hctOXHOhXSKShzue +vMUSW6h5zx2K/X8rmcMwYcV3LheEltAVcyPLvBXD14RLvcSQdv5fQ0qJFbxwk7oGzi7 mzmM8mf3bzPGkHWsMnwlrVoOhkoH+MTXJbQgSbT2LSYnoWX5W10EBMOgSu17FqBS5zvo jCxyo/PmzaHpb+2Nis5uWBcVfx4qRxRuz7TEflahBUgl24MTFU1SLAGOOyp8hXMNgu4G /kMhkoV/+XcNgD1I/B3JvBr7s8+bh7ylPaWQwUUYHGzRKEjHiBdH6u4pF6OvsOMGQyzZ 81+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697815447; x=1698420247; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AkQEX6C2wW1mPOWLXApStdvqFKYQwdr8AV6yMr5GZQk=; b=VE9s95LB1FW83vIJh3HjElBi10B3vxFmi4+8tjwDOblvRXQRuI28DpqY162OSFBM7Z muh+2IE0ylJUxSV7gumNm3aVD50yB5sv29AzSnDR00GLofNgujhz5QFM4C847rsVzs0S CrI2kJSFjg/1oiV1Mv4Hdf6ea0Dy6cESjNui3pTDfmCF3nDZ/jrjrOciJ/l0VBFJ3QYl vtHWUNHjyyndlIZ1e0HlZKiJ0q0WQdkrTLim/NsqLMKJgCR9pGN5QxgE/4Ub37NPcfV+ eVXWEfK8bFVxQfxWbOTkRgnZRTHnvRQXBCDI2oTFE8XHS7NcpkUIP4BTFPlUbfTkDemy P4jw== X-Gm-Message-State: AOJu0Yw31c+9z6xQBT40ysXrFl0uGZoEKwPQCswUpLF8wJkUjfj5om1T scjlvn89DRm0DjEcCGo+CVkNZTZ6u/aB3PzD7o15ZV1A X-Google-Smtp-Source: AGHT+IGqS0TXLFwUD7S5nEwoFQEJQIsycHhGeuNESse1OwlaBO8Oz75kdppwCz4HGXI2JBDy61p6Ng== X-Received: by 2002:a17:902:c7c2:b0:1ca:7308:e43a with SMTP id r2-20020a170902c7c200b001ca7308e43amr1577340pla.47.1697815446622; Fri, 20 Oct 2023 08:24:06 -0700 (PDT) Received: from localhost.localdomain ([171.216.79.181]) by smtp.gmail.com with ESMTPSA id d4-20020a170902cec400b001c60d0a6d84sm1644824plg.127.2023.10.20.08.24.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 08:24:06 -0700 (PDT) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Juan Quintela , Peter Xu , Fabiano Rosas , Leonardo Bras , Thomas Huth , Laurent Vivier , Paolo Bonzini , Hyman Huang Subject: [v2 2/6] system/dirtylimit: Drop the reduplicative check Date: Fri, 20 Oct 2023 23:23:44 +0800 Message-Id: <31384f768279027560ab952ebc2bbff1ddb62531.1697815117.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::62d; envelope-from=yong.huang@smartx.com; helo=mail-pl1-x62d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Checking if dirty limit is in service is done by the dirtylimit_query_all function, drop the reduplicative check in the qmp_query_vcpu_dirty_limit function. Signed-off-by: Hyman Huang Reviewed-by: Fabiano Rosas --- system/dirtylimit.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/system/dirtylimit.c b/system/dirtylimit.c index 3666c4cb7c..495c7a7082 100644 --- a/system/dirtylimit.c +++ b/system/dirtylimit.c @@ -652,10 +652,6 @@ static struct DirtyLimitInfoList *dirtylimit_query_all(void) struct DirtyLimitInfoList *qmp_query_vcpu_dirty_limit(Error **errp) { - if (!dirtylimit_in_service()) { - return NULL; - } - return dirtylimit_query_all(); } From patchwork Fri Oct 20 15:23:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13430877 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 747EBCDB474 for ; Fri, 20 Oct 2023 15:27:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtrOC-0003Ac-BN; Fri, 20 Oct 2023 11:26:16 -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 1qtrO9-0002xi-Na for qemu-devel@nongnu.org; Fri, 20 Oct 2023 11:26:13 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtrO7-00065A-Pu for qemu-devel@nongnu.org; Fri, 20 Oct 2023 11:26:13 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1ca215cc713so6912625ad.3 for ; Fri, 20 Oct 2023 08:24:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1697815450; x=1698420250; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EK74mlAI7dxIh9RPbUZnzOduNjpDoFgT9Je4rl8rE8M=; b=Tp06cpfk73vHMjWIvLCSydI5qPnzB0ZKqE+hlu0OrZ2YGhrKoFrizpEN0kljrDm3vA eh7ysFtxMMrDvSfJqvon7iTxBbTI5XIpEPodnCbgmErLuHX/Xy8SQvWjURAk/Pl/n61r pUBWFABRMa2Kon30gN8R3FlkZ578cvAL024SD5sLYXLAW3MG7CBr1xZLpCO9E5Mcr4UA OdNzjR1z+FWy6sKaff3KTbxrcY2A0OFGgr/G6W30COZ2Kjr13ORwdZe7cDtFGyPEkNGf ySoL81rtFsKFzCh/x1Z7JVvgeF37H9Qx5NeItSPdFBtDAOMJCG0CEe3IkiTNEwGVXNHj 0a7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697815450; x=1698420250; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EK74mlAI7dxIh9RPbUZnzOduNjpDoFgT9Je4rl8rE8M=; b=m5GxAUlUyP+pMGSmk2uvtAyeZvCynqIxr2RwKch6T/QPyDVnt9kDI3oIDXQJaZE4/c 8RdoByc/l6ehPOBy5Beu/bZ+yFqQa2yrPX+W0dlhPc5MwO6O+EmiiOSVvmaf7wfK+Efk 2dl8X8H9SI7fT5UNjbBfGrGLa/bPkS5csuFUI3lre2C2wFopr/4fG9MsxMKJ0VNqvMpK /dfipMe2e/dZtg97FGDsbiUJj1MPr2CqxgIRGjiIEyXkMyh/8LZbtT6nGm7t1zfb30Bq jrF64U7UXFRZFwGpFA0yW6oztsAtBAhabzSD60BlhHqiWbiVMx9HgmMn8haHEKQg89az y0cA== X-Gm-Message-State: AOJu0Yxl02wYyswAETaJIgANQLF3VXMCMF8PZ5NMUiKtD59JGbDSHMkc 9KXxm9VTI9e8JWez08QPwLK2eUEAtd7J1ZuUkPPQ/6uM X-Google-Smtp-Source: AGHT+IE9m22p3KPsNa5LK4QsxbS2EHuwkz9Qnj3MLGaDheJdz4HD4ZH+ZGftyNV0kHOWLT8qOFUayw== X-Received: by 2002:a17:902:ca14:b0:1ca:8629:829b with SMTP id w20-20020a170902ca1400b001ca8629829bmr1781822pld.50.1697815449732; Fri, 20 Oct 2023 08:24:09 -0700 (PDT) Received: from localhost.localdomain ([171.216.79.181]) by smtp.gmail.com with ESMTPSA id d4-20020a170902cec400b001c60d0a6d84sm1644824plg.127.2023.10.20.08.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 08:24:09 -0700 (PDT) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Juan Quintela , Peter Xu , Fabiano Rosas , Leonardo Bras , Thomas Huth , Laurent Vivier , Paolo Bonzini , Hyman Huang Subject: [v2 3/6] tests: Add migration dirty-limit capability test Date: Fri, 20 Oct 2023 23:23:45 +0800 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::629; envelope-from=yong.huang@smartx.com; helo=mail-pl1-x629.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Add migration dirty-limit capability test if kernel support dirty ring. Migration dirty-limit capability introduce dirty limit capability, two parameters: x-vcpu-dirty-limit-period and vcpu-dirty-limit are introduced to implement the live migration with dirty limit. The test case does the following things: 1. start src, dst vm and enable dirty-limit capability 2. start migrate and set cancel it to check if dirty limit stop working. 3. restart dst vm 4. start migrate and enable dirty-limit capability 5. check if migration satisfy the convergence condition during pre-switchover phase. Note that this test case involves many passes, so it runs in slow mode only. Signed-off-by: Hyman Huang Acked-by: Peter Xu Reviewed-by: Fabiano Rosas --- tests/qtest/migration-test.c | 164 +++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index e1c110537b..8f966c4d25 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -2943,6 +2943,166 @@ static void test_vcpu_dirty_limit(void) dirtylimit_stop_vm(vm); } +static void migrate_dirty_limit_wait_showup(QTestState *from, + const int64_t period, + const int64_t value) +{ + /* Enable dirty limit capability */ + migrate_set_capability(from, "dirty-limit", true); + + /* Set dirty limit parameters */ + migrate_set_parameter_int(from, "x-vcpu-dirty-limit-period", period); + migrate_set_parameter_int(from, "vcpu-dirty-limit", value); + + /* Make sure migrate can't converge */ + migrate_ensure_non_converge(from); + + /* To check limit rate after precopy */ + migrate_set_capability(from, "pause-before-switchover", true); + + /* Wait for the serial output from the source */ + wait_for_serial("src_serial"); +} + +/* + * This test does: + * source destination + * start vm + * start incoming vm + * migrate + * wait dirty limit to begin + * cancel migrate + * cancellation check + * restart incoming vm + * migrate + * wait dirty limit to begin + * wait pre-switchover event + * convergence condition check + * + * And see if dirty limit migration works correctly. + * This test case involves many passes, so it runs in slow mode only. + */ +static void test_migrate_dirty_limit(void) +{ + g_autofree char *uri = g_strdup_printf("unix:%s/migsocket", tmpfs); + QTestState *from, *to; + int64_t remaining; + uint64_t throttle_us_per_full; + /* + * We want the test to be stable and as fast as possible. + * E.g., with 1Gb/s bandwith migration may pass without dirty limit, + * so we need to decrease a bandwidth. + */ + const int64_t dirtylimit_period = 1000, dirtylimit_value = 50; + const int64_t max_bandwidth = 400000000; /* ~400Mb/s */ + const int64_t downtime_limit = 250; /* 250ms */ + /* + * We migrate through unix-socket (> 500Mb/s). + * Thus, expected migration speed ~= bandwidth limit (< 500Mb/s). + * So, we can predict expected_threshold + */ + const int64_t expected_threshold = max_bandwidth * downtime_limit / 1000; + int max_try_count = 10; + MigrateCommon args = { + .start = { + .hide_stderr = true, + .use_dirty_ring = true, + }, + .listen_uri = uri, + .connect_uri = uri, + }; + + /* Start src, dst vm */ + if (test_migrate_start(&from, &to, args.listen_uri, &args.start)) { + return; + } + + /* Prepare for dirty limit migration and wait src vm show up */ + migrate_dirty_limit_wait_showup(from, dirtylimit_period, dirtylimit_value); + + /* Start migrate */ + migrate_qmp(from, uri, "{}"); + + /* Wait for dirty limit throttle begin */ + throttle_us_per_full = 0; + while (throttle_us_per_full == 0) { + throttle_us_per_full = + read_migrate_property_int(from, "dirty-limit-throttle-time-per-round"); + usleep(100); + g_assert_false(got_src_stop); + } + + /* Now cancel migrate and wait for dirty limit throttle switch off */ + migrate_cancel(from); + wait_for_migration_status(from, "cancelled", NULL); + + /* Check if dirty limit throttle switched off, set timeout 1ms */ + do { + throttle_us_per_full = + read_migrate_property_int(from, "dirty-limit-throttle-time-per-round"); + usleep(100); + g_assert_false(got_src_stop); + } while (throttle_us_per_full != 0 && --max_try_count); + + /* Assert dirty limit is not in service */ + g_assert_cmpint(throttle_us_per_full, ==, 0); + + args = (MigrateCommon) { + .start = { + .only_target = true, + .use_dirty_ring = true, + }, + .listen_uri = uri, + .connect_uri = uri, + }; + + /* Restart dst vm, src vm already show up so we needn't wait anymore */ + if (test_migrate_start(&from, &to, args.listen_uri, &args.start)) { + return; + } + + /* Start migrate */ + migrate_qmp(from, uri, "{}"); + + /* Wait for dirty limit throttle begin */ + throttle_us_per_full = 0; + while (throttle_us_per_full == 0) { + throttle_us_per_full = + read_migrate_property_int(from, "dirty-limit-throttle-time-per-round"); + usleep(100); + g_assert_false(got_src_stop); + } + + /* + * The dirty limit rate should equals the return value of + * query-vcpu-dirty-limit if dirty limit cap set + */ + g_assert_cmpint(dirtylimit_value, ==, get_limit_rate(from)); + + /* Now, we have tested if dirty limit works, let it converge */ + migrate_set_parameter_int(from, "downtime-limit", downtime_limit); + migrate_set_parameter_int(from, "max-bandwidth", max_bandwidth); + + /* + * Wait for pre-switchover status to check if migration + * satisfy the convergence condition + */ + wait_for_migration_status(from, "pre-switchover", NULL); + + remaining = read_ram_property_int(from, "remaining"); + g_assert_cmpint(remaining, <, + (expected_threshold + expected_threshold / 100)); + + migrate_continue(from, "pre-switchover"); + + qtest_qmp_eventwait(to, "RESUME"); + + wait_for_serial("dest_serial"); + wait_for_migration_complete(from); + + test_migrate_end(from, to, true); +} + static bool kvm_dirty_ring_supported(void) { #if defined(__linux__) && defined(HOST_X86_64) @@ -3125,6 +3285,10 @@ int main(int argc, char **argv) */ if (g_test_slow()) { qtest_add_func("/migration/auto_converge", test_migrate_auto_converge); + if (g_str_equal(arch, "x86_64") && + has_kvm && kvm_dirty_ring_supported()) { + qtest_add_func("/migration/dirty_limit", test_migrate_dirty_limit); + } } qtest_add_func("/migration/multifd/tcp/plain/none", test_multifd_tcp_none); From patchwork Fri Oct 20 15:23:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13430878 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 43FB0C001DF for ; Fri, 20 Oct 2023 15:27:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtrOE-0003MI-SS; Fri, 20 Oct 2023 11:26:18 -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 1qtrOC-0003Ax-GR for qemu-devel@nongnu.org; Fri, 20 Oct 2023 11:26:16 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtrOA-00068G-Q0 for qemu-devel@nongnu.org; Fri, 20 Oct 2023 11:26:16 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1c9e06f058bso15817805ad.0 for ; Fri, 20 Oct 2023 08:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1697815453; x=1698420253; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iTy7noxqV1LuTlA1Rq7Lol31NdpvxYfwqN+SZtKW4VA=; b=1P21k5waJEqibW2FSJpaQWJp+/nsWfUwPVvKGS4V42q3ENt0pWpaYzeyo8CP245W5b NSChzY8mVfvU8vCmMefiPaAoNOeTQ++Pmerco7L4RAXXagY3pPCte3G/F920Li8oVTGm PXJvwDnFnze+VSUykQ9jzPjs+mQP1Ub1qa9HDz3/AfSLq+ZYIE3N56a248qSpoxO802u abvaI03VVAyQl+HjThYrCPYPXklJJHo/RDYKIdgUhSSFV9rd/vR+DTDQZKPZu5mPuI52 DnydZoydjvGkjN+LVGlibxRBdoH5ASx1Nf5PwGXp+0Lnuy0UhVtlb5qrbTL7ii3q5HKa owag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697815453; x=1698420253; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iTy7noxqV1LuTlA1Rq7Lol31NdpvxYfwqN+SZtKW4VA=; b=QqErz2kazuI5/9hAclYQv2EBWiJP8CIvlBviOsRhgtI57fDHaduerrUzj2VvZoUppE r81NwprMN+z8BPXkR/JaiSz9mWvjTGReTM2zLAmJYxbfAuooQ0iVJVedgAgcBQkUZGVG X4C90rcvd4VqoIfcZpuguS240e15pc2wd+mwkc9wDXaiQOXA/O7LZtazqhyMHY9kaxUu zVYc1JjZxopm+2OvOMU4aOEX8nzrsct7LjV6ygb+sNxsPcUviXXTYL/c0vFzQzr+Sknl Rsp1rXW5Nk1cVplvoDAOjYOml/cdujaSxvgnW0onlCqK6D2UyfbXf2LQOQiKNrGFupLO JhmA== X-Gm-Message-State: AOJu0YyuZCxN0I56Jnoboc9g2wOOcdlsjNP4Ekw8LtSVIfNJHS8/IOmh 1ii0KkFs76Le1DUe8U9GtOFIyjzjk8NTGYcnFdyS3WEL X-Google-Smtp-Source: AGHT+IFKR0KcSeAjgEA1w25Wup+FuDvZxM19b+1AlOTFKX7x4HK04U3sEOTuSn1RJZqQuTqczWFZ3g== X-Received: by 2002:a17:902:d4c7:b0:1ca:3cd7:eadb with SMTP id o7-20020a170902d4c700b001ca3cd7eadbmr2558355plg.9.1697815453082; Fri, 20 Oct 2023 08:24:13 -0700 (PDT) Received: from localhost.localdomain ([171.216.79.181]) by smtp.gmail.com with ESMTPSA id d4-20020a170902cec400b001c60d0a6d84sm1644824plg.127.2023.10.20.08.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 08:24:12 -0700 (PDT) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Juan Quintela , Peter Xu , Fabiano Rosas , Leonardo Bras , Thomas Huth , Laurent Vivier , Paolo Bonzini , Hyman Huang Subject: [v2 4/6] tests/migration: Introduce dirty-ring-size option into guestperf Date: Fri, 20 Oct 2023 23:23:46 +0800 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::62f; envelope-from=yong.huang@smartx.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Dirty ring size configuration is not supported by guestperf tool. Introduce dirty-ring-size (ranges in [1024, 65536]) option so developers can play with dirty-ring and dirty-limit feature easier. To set dirty ring size with 4096 during migration test: $ ./tests/migration/guestperf.py --dirty-ring-size 4096 xxx Signed-off-by: Hyman Huang Reviewed-by: Fabiano Rosas --- tests/migration/guestperf/engine.py | 6 +++++- tests/migration/guestperf/hardware.py | 8 ++++++-- tests/migration/guestperf/shell.py | 6 +++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/migration/guestperf/engine.py b/tests/migration/guestperf/engine.py index da96ca034a..aabf6de4d9 100644 --- a/tests/migration/guestperf/engine.py +++ b/tests/migration/guestperf/engine.py @@ -325,7 +325,6 @@ def _get_common_args(self, hardware, tunnelled=False): cmdline = "'" + cmdline + "'" argv = [ - "-accel", "kvm", "-cpu", "host", "-kernel", self._kernel, "-initrd", self._initrd, @@ -333,6 +332,11 @@ def _get_common_args(self, hardware, tunnelled=False): "-m", str((hardware._mem * 1024) + 512), "-smp", str(hardware._cpus), ] + if hardware._dirty_ring_size: + argv.extend(["-accel", "kvm,dirty-ring-size=%s" % + hardware._dirty_ring_size]) + else: + argv.extend(["-accel", "kvm"]) argv.extend(self._get_qemu_serial_args()) diff --git a/tests/migration/guestperf/hardware.py b/tests/migration/guestperf/hardware.py index 3145785ffd..f779cc050b 100644 --- a/tests/migration/guestperf/hardware.py +++ b/tests/migration/guestperf/hardware.py @@ -23,7 +23,8 @@ def __init__(self, cpus=1, mem=1, src_cpu_bind=None, src_mem_bind=None, dst_cpu_bind=None, dst_mem_bind=None, prealloc_pages = False, - huge_pages=False, locked_pages=False): + huge_pages=False, locked_pages=False, + dirty_ring_size=0): self._cpus = cpus self._mem = mem # GiB self._src_mem_bind = src_mem_bind # List of NUMA nodes @@ -33,6 +34,7 @@ def __init__(self, cpus=1, mem=1, self._prealloc_pages = prealloc_pages self._huge_pages = huge_pages self._locked_pages = locked_pages + self._dirty_ring_size = dirty_ring_size def serialize(self): @@ -46,6 +48,7 @@ def serialize(self): "prealloc_pages": self._prealloc_pages, "huge_pages": self._huge_pages, "locked_pages": self._locked_pages, + "dirty_ring_size": self._dirty_ring_size, } @classmethod @@ -59,4 +62,5 @@ def deserialize(cls, data): data["dst_mem_bind"], data["prealloc_pages"], data["huge_pages"], - data["locked_pages"]) + data["locked_pages"], + data["dirty_ring_size"]) diff --git a/tests/migration/guestperf/shell.py b/tests/migration/guestperf/shell.py index 8a809e3dda..7d6b8cd7cf 100644 --- a/tests/migration/guestperf/shell.py +++ b/tests/migration/guestperf/shell.py @@ -60,6 +60,8 @@ def __init__(self): parser.add_argument("--prealloc-pages", dest="prealloc_pages", default=False) parser.add_argument("--huge-pages", dest="huge_pages", default=False) parser.add_argument("--locked-pages", dest="locked_pages", default=False) + parser.add_argument("--dirty-ring-size", dest="dirty_ring_size", + default=0, type=int) self._parser = parser @@ -89,7 +91,9 @@ def split_map(value): locked_pages=args.locked_pages, huge_pages=args.huge_pages, - prealloc_pages=args.prealloc_pages) + prealloc_pages=args.prealloc_pages, + + dirty_ring_size=args.dirty_ring_size) class Shell(BaseShell): From patchwork Fri Oct 20 15:23:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13430880 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 4ECACC001DF for ; Fri, 20 Oct 2023 15:27:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtrOI-0003QR-7l; Fri, 20 Oct 2023 11:26:22 -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 1qtrOG-0003Pz-4X for qemu-devel@nongnu.org; Fri, 20 Oct 2023 11:26:20 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtrOE-00068K-0y for qemu-devel@nongnu.org; Fri, 20 Oct 2023 11:26:19 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6b7f0170d7bso869340b3a.2 for ; Fri, 20 Oct 2023 08:24:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1697815456; x=1698420256; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zK7JUPjMc/eda4hGQUyZLj9/LbQ1yYC1yTNO8lriRFA=; b=dRwF9cSXB6omQUX0+DLNXA/aUtH+Y4w9z8rVdFT2LrO8TzjW9uVI0x/Y9FT7KhdYgh AvbswkR7A+UHOzGTT+OfrOFq2j4OTKauo7DHl/FHiMv2RyuI01WZt80bWGDbHLqTTSlU SW2fk5LXDIk5n6HVnDnoKk06su+9oWSZR4ON+6XPxsohCBErDMNKSKPgDGooJDOsehrg 39gdV2m2iAUO3ZhPUgW0ef7+ufw3/4gezNi3qjSh0oICv64q+lqKcUTyhUEOb4UzDDn/ hWXb7svWtXATH56KGLnu/CnFg/7OomqKhCNlsxfpkQVpzeXm+jMF3C31ph8uDsTotFyy fEuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697815456; x=1698420256; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zK7JUPjMc/eda4hGQUyZLj9/LbQ1yYC1yTNO8lriRFA=; b=X18Ix31H0/43gphxghNDTttGKCbB0aSnkENxbl33FgKdMaRMhGGmqGmIql1SyitYUj 138yFLD0BRQ3ppKEiVgWyu5+L/AHKpA7GAlJ008lfI7Y07vFfX1AIcbtMS91qcd9oFii SUDBdcVLk4L1RCYCLbSb7U2kGCpdQ0Ngp6JPaZlgQi/5h3TzcXh86BWnKDg1eYOcnBgo 73IrdPP8VL2bEVNZUAQ0uh0TzV8SqSIdGFX+D7HbRpp0mfc8UpNH9J75Ziz6CmG4pUpL SCp60dqVaiF1noyHS6NnXrYIQdlu9t8Nak3ym9lM6RzWOYyNxyHfkoYesRTkaH1kewWf i/dw== X-Gm-Message-State: AOJu0YwTJ1AyrD1CdrXbWkP0MX5LkuXu93wUfdQ9Ax7C54gv/ZD45IOK KIBE/2H55L3r3ghGJ8P1sBvzKOAX3Q6lh4qp/sAgfYae X-Google-Smtp-Source: AGHT+IEWNG3f9g+31r4C0ODlsqEeJbkYO/LM7MN1vxdTRT0Xn+i/1mOGeyoFgrB081pI6vVE50BBFw== X-Received: by 2002:a05:6a20:7483:b0:17b:e0a3:f6f4 with SMTP id p3-20020a056a20748300b0017be0a3f6f4mr2300471pzd.25.1697815456215; Fri, 20 Oct 2023 08:24:16 -0700 (PDT) Received: from localhost.localdomain ([171.216.79.181]) by smtp.gmail.com with ESMTPSA id d4-20020a170902cec400b001c60d0a6d84sm1644824plg.127.2023.10.20.08.24.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 08:24:15 -0700 (PDT) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Juan Quintela , Peter Xu , Fabiano Rosas , Leonardo Bras , Thomas Huth , Laurent Vivier , Paolo Bonzini , Hyman Huang Subject: [v2 5/6] tests/migration: Introduce dirty-limit into guestperf Date: Fri, 20 Oct 2023 23:23:47 +0800 Message-Id: <516e7a55dfc6e33d33510be37eb24223de5dc072.1697815117.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::435; envelope-from=yong.huang@smartx.com; helo=mail-pf1-x435.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Currently, guestperf does not cover the dirty-limit migration, support this feature. Note that dirty-limit requires 'dirty-ring-size' set. To enable dirty-limit, setting x-vcpu-dirty-limit-period as 500ms and x-vcpu-dirty-limit as 10MB/s: $ ./tests/migration/guestperf.py \ --dirty-ring-size 4096 \ --dirty-limit --x-vcpu-dirty-limit-period 500 \ --vcpu-dirty-limit 10 --output output.json \ To run the entire standardized set of dirty-limit-enabled comparisons, with unix migration: $ ./tests/migration/guestperf-batch.py \ --dirty-ring-size 4096 \ --dst-host localhost --transport unix \ --filter compr-dirty-limit* --output outputdir Signed-off-by: Hyman Huang Reviewed-by: Fabiano Rosas --- tests/migration/guestperf/comparison.py | 23 +++++++++++++++++++++++ tests/migration/guestperf/engine.py | 17 +++++++++++++++++ tests/migration/guestperf/progress.py | 16 ++++++++++++++-- tests/migration/guestperf/scenario.py | 11 ++++++++++- tests/migration/guestperf/shell.py | 18 +++++++++++++++++- 5 files changed, 81 insertions(+), 4 deletions(-) diff --git a/tests/migration/guestperf/comparison.py b/tests/migration/guestperf/comparison.py index c03b3f6d7e..42cc0372d1 100644 --- a/tests/migration/guestperf/comparison.py +++ b/tests/migration/guestperf/comparison.py @@ -135,4 +135,27 @@ def __init__(self, name, scenarios): Scenario("compr-multifd-channels-64", multifd=True, multifd_channels=64), ]), + + # Looking at effect of dirty-limit with + # varying x_vcpu_dirty_limit_period + Comparison("compr-dirty-limit-period", scenarios = [ + Scenario("compr-dirty-limit-period-500", + dirty_limit=True, x_vcpu_dirty_limit_period=500), + Scenario("compr-dirty-limit-period-800", + dirty_limit=True, x_vcpu_dirty_limit_period=800), + Scenario("compr-dirty-limit-period-1000", + dirty_limit=True, x_vcpu_dirty_limit_period=1000), + ]), + + + # Looking at effect of dirty-limit with + # varying vcpu_dirty_limit + Comparison("compr-dirty-limit", scenarios = [ + Scenario("compr-dirty-limit-10MB", + dirty_limit=True, vcpu_dirty_limit=10), + Scenario("compr-dirty-limit-20MB", + dirty_limit=True, vcpu_dirty_limit=20), + Scenario("compr-dirty-limit-50MB", + dirty_limit=True, vcpu_dirty_limit=50), + ]), ] diff --git a/tests/migration/guestperf/engine.py b/tests/migration/guestperf/engine.py index aabf6de4d9..608d7270f6 100644 --- a/tests/migration/guestperf/engine.py +++ b/tests/migration/guestperf/engine.py @@ -102,6 +102,8 @@ def _migrate_progress(self, vm): info.get("expected-downtime", 0), info.get("setup-time", 0), info.get("cpu-throttle-percentage", 0), + info.get("dirty-limit-throttle-time-per-round", 0), + info.get("dirty-limit-ring-full-time", 0), ) def _migrate(self, hardware, scenario, src, dst, connect_uri): @@ -203,6 +205,21 @@ def _migrate(self, hardware, scenario, src, dst, connect_uri): resp = dst.cmd("migrate-set-parameters", multifd_channels=scenario._multifd_channels) + if scenario._dirty_limit: + if not hardware._dirty_ring_size: + raise Exception("dirty ring size must be configured when " + "testing dirty limit migration") + + resp = src.cmd("migrate-set-capabilities", + capabilities = [ + { "capability": "dirty-limit", + "state": True } + ]) + resp = src.cmd("migrate-set-parameters", + x_vcpu_dirty_limit_period=scenario._x_vcpu_dirty_limit_period) + resp = src.cmd("migrate-set-parameters", + vcpu_dirty_limit=scenario._vcpu_dirty_limit) + resp = src.cmd("migrate", uri=connect_uri) post_copy = False diff --git a/tests/migration/guestperf/progress.py b/tests/migration/guestperf/progress.py index ab1ee57273..d490584217 100644 --- a/tests/migration/guestperf/progress.py +++ b/tests/migration/guestperf/progress.py @@ -81,7 +81,9 @@ def __init__(self, downtime, downtime_expected, setup_time, - throttle_pcent): + throttle_pcent, + dirty_limit_throttle_time_per_round, + dirty_limit_ring_full_time): self._status = status self._ram = ram @@ -91,6 +93,10 @@ def __init__(self, self._downtime_expected = downtime_expected self._setup_time = setup_time self._throttle_pcent = throttle_pcent + self._dirty_limit_throttle_time_per_round = \ + dirty_limit_throttle_time_per_round + self._dirty_limit_ring_full_time = \ + dirty_limit_ring_full_time def serialize(self): return { @@ -102,6 +108,10 @@ def serialize(self): "downtime_expected": self._downtime_expected, "setup_time": self._setup_time, "throttle_pcent": self._throttle_pcent, + "dirty_limit_throttle_time_per_round": + self._dirty_limit_throttle_time_per_round, + "dirty_limit_ring_full_time": + self._dirty_limit_ring_full_time, } @classmethod @@ -114,4 +124,6 @@ def deserialize(cls, data): data["downtime"], data["downtime_expected"], data["setup_time"], - data["throttle_pcent"]) + data["throttle_pcent"], + data["dirty_limit_throttle_time_per_round"], + data["dirty_limit_ring_full_time"]) diff --git a/tests/migration/guestperf/scenario.py b/tests/migration/guestperf/scenario.py index de70d9b2f5..154c4f5d5f 100644 --- a/tests/migration/guestperf/scenario.py +++ b/tests/migration/guestperf/scenario.py @@ -30,7 +30,9 @@ def __init__(self, name, auto_converge=False, auto_converge_step=10, compression_mt=False, compression_mt_threads=1, compression_xbzrle=False, compression_xbzrle_cache=10, - multifd=False, multifd_channels=2): + multifd=False, multifd_channels=2, + dirty_limit=False, x_vcpu_dirty_limit_period=500, + vcpu_dirty_limit=1): self._name = name @@ -60,6 +62,10 @@ def __init__(self, name, self._multifd = multifd self._multifd_channels = multifd_channels + self._dirty_limit = dirty_limit + self._x_vcpu_dirty_limit_period = x_vcpu_dirty_limit_period + self._vcpu_dirty_limit = vcpu_dirty_limit + def serialize(self): return { "name": self._name, @@ -79,6 +85,9 @@ def serialize(self): "compression_xbzrle_cache": self._compression_xbzrle_cache, "multifd": self._multifd, "multifd_channels": self._multifd_channels, + "dirty_limit": self._dirty_limit, + "x_vcpu_dirty_limit_period": self._x_vcpu_dirty_limit_period, + "vcpu_dirty_limit": self._vcpu_dirty_limit, } @classmethod diff --git a/tests/migration/guestperf/shell.py b/tests/migration/guestperf/shell.py index 7d6b8cd7cf..c85d89efec 100644 --- a/tests/migration/guestperf/shell.py +++ b/tests/migration/guestperf/shell.py @@ -131,6 +131,17 @@ def __init__(self): parser.add_argument("--multifd-channels", dest="multifd_channels", default=2, type=int) + parser.add_argument("--dirty-limit", dest="dirty_limit", default=False, + action="store_true") + + parser.add_argument("--x-vcpu-dirty-limit-period", + dest="x_vcpu_dirty_limit_period", + default=500, type=int) + + parser.add_argument("--vcpu-dirty-limit", + dest="vcpu_dirty_limit", + default=1, type=int) + def get_scenario(self, args): return Scenario(name="perfreport", downtime=args.downtime, @@ -154,7 +165,12 @@ def get_scenario(self, args): compression_xbzrle_cache=args.compression_xbzrle_cache, multifd=args.multifd, - multifd_channels=args.multifd_channels) + multifd_channels=args.multifd_channels, + + dirty_limit=args.dirty_limit, + x_vcpu_dirty_limit_period=\ + args.x_vcpu_dirty_limit_period, + vcpu_dirty_limit=args.vcpu_dirty_limit) def run(self, argv): args = self._parser.parse_args(argv) From patchwork Fri Oct 20 15:23:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13430875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2E713C001DF for ; Fri, 20 Oct 2023 15:27:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtrOK-0003UU-SF; Fri, 20 Oct 2023 11:26:24 -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 1qtrOJ-0003Ra-6X for qemu-devel@nongnu.org; Fri, 20 Oct 2023 11:26:23 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtrOH-0006Bu-Kc for qemu-devel@nongnu.org; Fri, 20 Oct 2023 11:26:22 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1c9d3a21f7aso7556045ad.2 for ; Fri, 20 Oct 2023 08:24:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1697815460; x=1698420260; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r3LoJaZtBc7uIbn5BRVxl3tXOWLKI1Lh4C9OuQJm92w=; b=poGcqkFmr/Lcjy1Ib9QEk7czk5yScCyBRZHoRj6Xy5Zlxm+VrpNdFdL8+7JxfNXBOa 63bHNF6i5kk5DuwQbcIUNVX279wIDFUjbra7cu4MbESRm+/DgmXniurJXvXtlBIzae5h O970c6i59NEN0IsYy7p/Kr9N16nVBFo4YN9Q11OwzeB2CWy08vmGG2m+D2Reot+yntQp SnNkAt5Bf+mjH3IQn2aeq69kxMueDnKgur8yb4oKdmcLD+NJ+sasY1O5ur8w7csXY7F1 4suxU+6JpXPlNGUwS3YWVj+x1O+3JXD204rVvObrQOcXPcbVM+S5Kkw4QF0OPJsFBht/ JUvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697815460; x=1698420260; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r3LoJaZtBc7uIbn5BRVxl3tXOWLKI1Lh4C9OuQJm92w=; b=l8SQYuXSJN+tqVGRKSnYdgoHdwwfpFuXkiaIdA0A+qlkJiKvyJRUYE8a3U0OlVEmbw xQH93AnW/kJK8Sg0HS7tbVYFw2dj9AjY/rjk4FXW66HW5xMAjkwm2Ur2DWDDtQTY6I6U 0HuZBfHvifHu/MF1ENecUtxG4R8Lme4oaCH/lTxoVcuWJA+Lgr3buEfTmLTfmuX+Xpj9 10TPV2m6ZkGWdvzMAbY96pkxS+8pVD98pac5U/QHrgykfIJVlhdar8J/VOqy2q67/zGr Cfwsfdc5pO/TayezS9XSOCLw/RyBilkHsaYmg1rxAoLiLYg1Ed5M/feARQlB6XiwWaRS pu1g== X-Gm-Message-State: AOJu0Yy5xp121nEbxjD3x60MZLLeJnI7R4jZBQV9Ri3Xh2pfFmkHyu3Q 7G//O/LH38Jzkj2RAf6pO3az1+mXge24LZ9t35cuxBJ3 X-Google-Smtp-Source: AGHT+IEuhN7ylgU5q4JOOmGhMQiVI/ybNca1TU7QpNQJG0Qs2Drijy7gZE4AjK7Y0ypAKYPmA/Q0iA== X-Received: by 2002:a17:902:e551:b0:1c9:d358:b3cd with SMTP id n17-20020a170902e55100b001c9d358b3cdmr2469461plf.42.1697815460108; Fri, 20 Oct 2023 08:24:20 -0700 (PDT) Received: from localhost.localdomain ([171.216.79.181]) by smtp.gmail.com with ESMTPSA id d4-20020a170902cec400b001c60d0a6d84sm1644824plg.127.2023.10.20.08.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 08:24:19 -0700 (PDT) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Juan Quintela , Peter Xu , Fabiano Rosas , Leonardo Bras , Thomas Huth , Laurent Vivier , Paolo Bonzini , Hyman Huang Subject: [v2 6/6] docs/migration: Add the dirty limit section Date: Fri, 20 Oct 2023 23:23:48 +0800 Message-Id: <36194a8a23d937392bf13d9fff8e898030c827a3.1697815117.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::62d; envelope-from=yong.huang@smartx.com; helo=mail-pl1-x62d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The dirty limit feature has been introduced since the 8.1 QEMU release but has not reflected in the document, add a section for that. Signed-off-by: Hyman Huang Reviewed-by: Fabiano Rosas --- docs/devel/migration.rst | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/docs/devel/migration.rst b/docs/devel/migration.rst index c3e1400c0c..347244af89 100644 --- a/docs/devel/migration.rst +++ b/docs/devel/migration.rst @@ -588,6 +588,77 @@ path. Return path - opened by main thread, written by main thread AND postcopy thread (protected by rp_mutex) +Dirty limit +===================== +The dirty limit, short for dirty page rate upper limit, is a new capability +introduced in the 8.1 QEMU release that uses a new algorithm based on the KVM +dirty ring to throttle down the guest during live migration. + +The algorithm framework is as follows: + +:: + + ------------------------------------------------------------------------------ + main --------------> throttle thread ------------> PREPARE(1) <-------- + thread \ | | + \ | | + \ V | + -\ CALCULATE(2) | + \ | | + \ | | + \ V | + \ SET PENALTY(3) ----- + -\ | + \ | + \ V + -> virtual CPU thread -------> ACCEPT PENALTY(4) + ------------------------------------------------------------------------------ + +When the qmp command qmp_set_vcpu_dirty_limit is called for the first time, +the QEMU main thread starts the throttle thread. The throttle thread, once +launched, executes the loop, which consists of three steps: + + - PREPARE (1) + + The entire work of PREPARE (1) is preparation for the second stage, + CALCULATE(2), as the name implies. It involves preparing the dirty + page rate value and the corresponding upper limit of the VM: + The dirty page rate is calculated via the KVM dirty ring mechanism, + which tells QEMU how many dirty pages a virtual CPU has had since the + last KVM_EXIT_DIRTY_RING_FULL exception; The dirty page rate upper + limit is specified by caller, therefore fetch it directly. + + - CALCULATE (2) + + Calculate a suitable sleep period for each virtual CPU, which will be + used to determine the penalty for the target virtual CPU. The + computation must be done carefully in order to reduce the dirty page + rate progressively down to the upper limit without oscillation. To + achieve this, two strategies are provided: the first is to add or + subtract sleep time based on the ratio of the current dirty page rate + to the limit, which is used when the current dirty page rate is far + from the limit; the second is to add or subtract a fixed time when + the current dirty page rate is close to the limit. + + - SET PENALTY (3) + + Set the sleep time for each virtual CPU that should be penalized based + on the results of the calculation supplied by step CALCULATE (2). + +After completing the three above stages, the throttle thread loops back +to step PREPARE (1) until the dirty limit is reached. + +On the other hand, each virtual CPU thread reads the sleep duration and +sleeps in the path of the KVM_EXIT_DIRTY_RING_FULL exception handler, that +is ACCEPT PENALTY (4). Virtual CPUs tied with writing processes will +obviously exit to the path and get penalized, whereas virtual CPUs involved +with read processes will not. + +In summary, thanks to the KVM dirty ring technology, the dirty limit +algorithm will restrict virtual CPUs as needed to keep their dirty page +rate inside the limit. This leads to more steady reading performance during +live migration and can aid in improving large guest responsiveness. + Postcopy ========