From patchwork Tue Oct 17 11:36:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13425053 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 7DC27CDB474 for ; Tue, 17 Oct 2023 11:39:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsiPj-00031k-KD; Tue, 17 Oct 2023 07:39:07 -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 1qsiPi-00031Y-Ca for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:06 -0400 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qsiPg-000159-1T for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:06 -0400 Received: by mail-ot1-x332.google.com with SMTP id 46e09a7af769-6c67060fdfaso3857730a34.2 for ; Tue, 17 Oct 2023 04:37:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1697542623; x=1698147423; 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=NZN3PZcjXAZrKvaLzoF/mqQnoItoBs27sZrKsshwE4s=; b=mvXCYDBi34BcNaQgLtzugUGKVcQfitn/1SKYKYouyePoCPdKgGes/ABY4oIHsjec32 fMaWtYkjI+eQ2ekuweWBylYSyr8x/7VaJpXNFpWfrvwTdNSHHaPzwrghHgm0dvRHts3f CTLK5/iOTqzUkeawLWmqUcKlzJaUeedbei6eiUOSPDnt1FitHJhfUjhykpeBdiBO4wjx 8geqCE9OVi0VH7e3EvCsKD348KNQ6cpjrbmnsJY1xydDWWSMlTxFGPmAT+pVtyuSrbu/ vwPivlqLE/MreXhp2hN3DaSIN9hVUcSJpkWp1qKkkEMdyzLEpw3DuZtiF3LDcIgET+Sf XHRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697542623; x=1698147423; 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=NZN3PZcjXAZrKvaLzoF/mqQnoItoBs27sZrKsshwE4s=; b=fxhBSdw5VusexHUT+r+2IQ6O/mjwdcJ4jOZqe/G62kvinIjugtF4vI3uMkZypZQegD iPy88BkPN3ZWDcskgLPEcEoL+DJLW9YCnyq6AoSHCq2S6YGINLkDsCQ98KevzY4C7RUO nO7PxFb7JfY1d8MZcW+V5oKzeNN0S9UQeUJP+mEST8/iB747DF08pEhjJsQsQYkZKsB5 rZxD8qLVU97xzzqCkabQRfzqL9Z8iclaKlqgD1A3Uabmsxj2GOKq9wYYV3D9hphjA4Df ZyhcNIUvr66hTtqby9oLSDA+OASrCpFf4Dap3dLwGOhTzL7eUSaQl2lDMp9zaOgxZdl0 s0pg== X-Gm-Message-State: AOJu0YwbNTWur8bQlNsCaJLQUBRrWKlswQhqwnBi4aNt6rfdJxL5qwqX IIAdAXwfm8UBy2NnhS/QJmWqY7KxltFqQSpisj9dwoK/ X-Google-Smtp-Source: AGHT+IHuANjDvuOmNZP89BifXKe3+8uw71sT0jIxoXk5To2bFdEJ3zD4XpDIBfyVlNV+EzZZ9qjsGw== X-Received: by 2002:a05:6830:18c3:b0:6c4:81d6:171b with SMTP id v3-20020a05683018c300b006c481d6171bmr2134957ote.21.1697542622742; Tue, 17 Oct 2023 04:37:02 -0700 (PDT) Received: from localhost.localdomain ([171.216.79.181]) by smtp.gmail.com with ESMTPSA id x28-20020aa79a5c000000b00692c5b1a731sm1198647pfj.186.2023.10.17.04.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:36:55 -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: [PATCH 1/6] system/dirtylimit: Fix a race situation Date: Tue, 17 Oct 2023 19:36:04 +0800 Message-Id: <69ad82c901244e55f05a157edd828914b057e084.1697502089.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::332; envelope-from=yong.huang@smartx.com; helo=mail-ot1-x332.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 Tue Oct 17 11:36:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13425057 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 2B6D2CDB483 for ; Tue, 17 Oct 2023 11:40:20 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsiPx-00034Y-FX; Tue, 17 Oct 2023 07:39:21 -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 1qsiPv-00034L-IE for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:19 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qsiPu-00016I-0u for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:19 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6be840283ceso231897b3a.3 for ; Tue, 17 Oct 2023 04:37:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1697542635; x=1698147435; 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=WRQRlUyCRNvmksYGbVPBdusDzt/xm0aUk10LnlLsi/M=; b=ZbHthgHNU4hKlJ+CQKG2nKJNkuHHIAN9k4Yb0Vf50I1Gb4Z1hn5qzO84BoJuDH+7un 4WvTA3iW+ItvSqXre9+3jFQOhueuTv/lkWnAyGM2FemLg8i3HXwRGsMgJDxn2a18hT6r WwCS4hPPwK1lHfIbeWBuwDD/9CMbBdUTKbWSpb837yCQjAA8/SO1sCgRYHadFHsIWUPl OIjIGfsvcSF1fwCF8A8dYJORkcpIEDNWoxlr+5P70a1+PkhDlUHXDq9eH2XW/VAJv/c+ HCY+qUNb/pH7PKwxj68bgSWDQBTqz7kwC2WjBwsxKgYcYccKmE/NzuZcczJ6ZyuczCaQ BX4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697542635; x=1698147435; 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=WRQRlUyCRNvmksYGbVPBdusDzt/xm0aUk10LnlLsi/M=; b=rM+YvBVinGbOrAhykLWZCB4tdKx/bq6dCwaLSzKNb6WGeM+HC944WxGAINNDj/MKJn HUkfIPEFK5AKSjRwaJcr3Ovm587JkTojiqY1TUSFUHXR4nUlHROXVKf7k0rBVIWERSis ElS6xNxHXbAbrCa6kcSG2QsqccMMr/kKWIYf2xdcRPJEZB+YFikm5z76SyHcXoRzesh/ JFdsIzWk1PzuaP8kFXwBnPNpJao866pl9MEvp4rRnr2c05TPZv3bdN3gSxJz49uQ+ZsP RmoLgYSNCupySW9g1tASSQECfJdrBlbkFEZqB5q4Ham9W8BqqcHUq7X9lrHcq8qkAZl4 F79Q== X-Gm-Message-State: AOJu0YxmlFMZbgBiquP9fSVCQbVlDyhzzaAqOqjxqCnhkV4KjubdyoDD uALvzXW5gVH4w2d5qcZ6gcAO6k9vPofqDQv2xzrfr3jt X-Google-Smtp-Source: AGHT+IHAf+Daq5qb6gfp59/uRTwgeCa7GHTdd6sAf7FFphHyNGz4XnRjjRFijeY7RJhkr+Ks0ipIyw== X-Received: by 2002:a05:6a00:1916:b0:68f:cc47:fcc8 with SMTP id y22-20020a056a00191600b0068fcc47fcc8mr1884172pfi.14.1697542635343; Tue, 17 Oct 2023 04:37:15 -0700 (PDT) Received: from localhost.localdomain ([171.216.79.181]) by smtp.gmail.com with ESMTPSA id x28-20020aa79a5c000000b00692c5b1a731sm1198647pfj.186.2023.10.17.04.37.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:37: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: [PATCH 2/6] system/dirtylimit: Drop the reduplicative check Date: Tue, 17 Oct 2023 19:36:05 +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::42d; envelope-from=yong.huang@smartx.com; helo=mail-pf1-x42d.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 Tue Oct 17 11:36:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13425054 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 376DBCDB482 for ; Tue, 17 Oct 2023 11:40:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsiQ5-0003Ew-1Y; Tue, 17 Oct 2023 07:39:29 -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 1qsiQ1-0003Cq-WE for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:26 -0400 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qsiPz-00016V-4z for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:25 -0400 Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-6c7b3adbeb6so3945383a34.0 for ; Tue, 17 Oct 2023 04:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1697542641; x=1698147441; 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=Ehp1MYiOGlbtKEcRvBdXtOiByY73o/NtSPCzDl6hhJ8=; b=vBibL7CBPlNH8UhnBrgzGWT8X2krnxjuMZ41QzPgzGGqAqEZx+rkIh9h2+S/Z5ySKk ISCCuwPTwWCwXpbZnyW/I4CDFnrcTOUJDDK3HsinLXxlYEA9FAXZAkymm7n8+Gps+UBA rBQ4y5RJlCJ8qHqNL6eBiLu4lkm6hM6cHMpLkaz6Ju8WZ6xc08q04p21o7nRTUPdrpQZ QLqsVnxfm11jem2EZWBpGtU1k2Lt6i/ZAtyKrbnqHsFVPosOxgDVuq6NB1SSfb72n4IU uOr/UJgIACYxCsWg+J/va8EdsGEJJ2GDjoqA58HbI3Ar1OCUjRIVp6ZKIOWLwlMXJvHh KHOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697542641; x=1698147441; 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=Ehp1MYiOGlbtKEcRvBdXtOiByY73o/NtSPCzDl6hhJ8=; b=jaUXSy4LwMCV7TIvqicXe6kGj40wl+PvRfArJksb6ZGrvOjl7HVbkCwyx3HSljDC1/ qV18xFfhjEZWRl9BTbPgdJZGHjckSmnZ3wdrcPs4OQGcjbf/iQJxDjQBnz3KNtcO9l4z yjDGsKwq0jG1QZ10KTY49lkwq5sJ6E8zO0CMsGS2PIIRit2VwW49MKCss8xb7oGFp1+A XRu9NkCkT48QMf59lpxTrrruo/c8eOi+P4T+EJJxabJzT02fSFUFOmns55OU12WsHLen U3Ve8GNrHaql/muxpVrBbVXVWqEnFxkQOvj6cFkGDwaldUc+CwOL2t3NRcrHBRBhqVAe Gg4g== X-Gm-Message-State: AOJu0Yx+0zKO9X+b1MB4Vo+CQo+V/YXfyi5SJW3Mjf1Nbzj2ahr+oi1k KrNdOe/GiUeXiUjPlYK8nMLL3Bgvq9nqcpDzwBmgMaAp X-Google-Smtp-Source: AGHT+IHo4r5o67YWjySquA+A9UK/qcveypt7GXwojTLJ7wI32blG9Sc02RYWXHOTpCuOpGkWlyU3nQ== X-Received: by 2002:a9d:7cc4:0:b0:6b9:b600:589 with SMTP id r4-20020a9d7cc4000000b006b9b6000589mr1916699otn.15.1697542641586; Tue, 17 Oct 2023 04:37:21 -0700 (PDT) Received: from localhost.localdomain ([171.216.79.181]) by smtp.gmail.com with ESMTPSA id x28-20020aa79a5c000000b00692c5b1a731sm1198647pfj.186.2023.10.17.04.37.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:37: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: [PATCH 3/6] tests: Add migration dirty-limit capability test Date: Tue, 17 Oct 2023 19:36:06 +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::32f; envelope-from=yong.huang@smartx.com; helo=mail-ot1-x32f.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 8eb2053dbb..5bd105f1a6 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -2747,6 +2747,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) @@ -2918,6 +3078,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 Tue Oct 17 11:36:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13425058 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 026BDCDB484 for ; Tue, 17 Oct 2023 11:40:19 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsiQ6-0003HG-4x; Tue, 17 Oct 2023 07:39:30 -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 1qsiQ4-0003F5-R5 for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:28 -0400 Received: from mail-oo1-xc34.google.com ([2607:f8b0:4864:20::c34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qsiQ2-00016r-Fe for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:28 -0400 Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-57be3d8e738so3177665eaf.1 for ; Tue, 17 Oct 2023 04:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1697542644; x=1698147444; 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=Fd5UKu5pUh4rVV/XswdUneTmN1ftFd2QhZwXacrFjF1jTCmdbvLeoX8eBkuHPIVtu4 fUi76W4qG4AYxH8+PU22ea3/wLJevHdfM0Yi1qzaPinYl76Kqhvhr2SLo/DoEN5bj6Qu GDUktZ8I6uSG3CpG6TvnWr6oDZI9qmwxkfrvxfngQECeGdKIxLqAyg48aZHjW+bV5HeJ dtFpp4KDH61nIUzhNjRjpVgMaWIKjLisrlbDd/Fl/L7SP88EVsxdeBtkmEH20cNN68PX U/YAsZSgtFWvAd5mH/i26Qm0SIQV6BvXijNsTd2YQmzlgTOCll3BYueLhxjXMTxy4jEh 9dPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697542644; x=1698147444; 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=TOmnjay5y7PzhweOKa2ZMshGyoZtNdQ/EmNpoUo0L+XQ1hv+cl7nl1bYNzas7FvGI3 H6F7AkDxWjvCOTSQ3avXQJpKaTsC5quXUPxC2fEJIW2kxlBlmuhK0XlWDhxaWYFZbwrl wqNwNe5a3A6eFTQzvTV2J3ukR2cHf6b9jJMtPZfyXO53sHlArUhonCbANdbbxHi58MI3 TOfjRAKBo0S+D5uqK9VwOxT+aL3s4uIt8Z5pEDN+09FuRQqbAVHc49ipHS5DMjuP/xoa RqBTr15Vuz3Jc5SvqxeOa/VmwNLZp6Lf4g6HBspGffFYDZhE+nrN0m1Z0WQHzZHy6J4i +gGQ== X-Gm-Message-State: AOJu0YwZOdiiyVtk/fpLLCNsh/UtR6MVFZKwRw60k+R40aUdKti91orM c+0vbDb8iOTK2iWD1zr5zo1qsIVCZWOLGoMI8cFDW2yB X-Google-Smtp-Source: AGHT+IHgLuGPLW6f0+Lfha5rCb/3S5D95LPeFhmzIxpQCvrjQ8qZYvtgbnCg8v+wOEFjbxEf9z8dSQ== X-Received: by 2002:a05:6358:7aa:b0:142:fd2b:da2e with SMTP id n42-20020a05635807aa00b00142fd2bda2emr1748958rwj.31.1697542644476; Tue, 17 Oct 2023 04:37:24 -0700 (PDT) Received: from localhost.localdomain ([171.216.79.181]) by smtp.gmail.com with ESMTPSA id x28-20020aa79a5c000000b00692c5b1a731sm1198647pfj.186.2023.10.17.04.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:37:23 -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: [PATCH 4/6] tests/migration: Introduce dirty-ring-size option into guestperf Date: Tue, 17 Oct 2023 19:36:07 +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::c34; envelope-from=yong.huang@smartx.com; helo=mail-oo1-xc34.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 --- 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 Tue Oct 17 11:36:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13425056 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 5F553C41513 for ; Tue, 17 Oct 2023 11:40:16 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsiQ8-0003JS-Jw; Tue, 17 Oct 2023 07:39:32 -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 1qsiQ6-0003Hb-Ul for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:30 -0400 Received: from mail-oo1-xc34.google.com ([2607:f8b0:4864:20::c34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qsiQ4-00017L-Vb for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:30 -0400 Received: by mail-oo1-xc34.google.com with SMTP id 006d021491bc7-57ba5f05395so3372945eaf.1 for ; Tue, 17 Oct 2023 04:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1697542647; x=1698147447; 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=kyt/uz4CGeQTIGVTEwICz2qFCLRaGNhPFJiWmUOn2XSL+MCYmvmaKRqMedEHeAwLtO 0nv/lZNuSR0yOZQJCCi1bnVmHE2w9oztSuP+dMC95RxL4sgQAnKnSMhC6p3tO3eL3+3K 29U0wrMpu3qTuTsHnNcSEhxkweSeSxX2sufTQ7tfBcoDCaMs3AH9HDPkhTAQVwOQLJeC +xGyU3F03Z7GGoYEq3vfv8wvrM69PgJpVkKY7JNNYuXWe7bhx1yGg71HoOd9Ox+msi5Z RvSduLDzLEFplPKWFUW5Dqco4RM9CVDC1/DGRTx6yq4SD1FNE2DKCGTVpy9Qn48oFXL1 bmrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697542647; x=1698147447; 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=bDyl/u3svBt1l9vrmcWGukuxiR8GDFP6Q+A8B+XwfdNfckziyJDaBy6xQJ9QiDR+yi 6kK9lr+JZfn3MHoAY34ynF8TDk0r8BsubDqyvbnFwIE36ND9bQ/cUzfVWILIUbiLjXYh /K7vRv2DpSuVDpU9v3avtW96vsTX9NPnGrQFuSRmlvYf9hT7bRypoFrqvyQy/v4kcNqY N4DjzsvM03ybWvs8SfCxnpTtSIp3jAInwhpQuyK34aVx5e860yYNF9cPgBvijDK5JqKM 6bByRsUktZgsjgJ/nbY0h4oTs6ET22fbPrcnR/w1af6Khfpet0PMp+QMEzGumit1g4nt DwsA== X-Gm-Message-State: AOJu0YzLdK6nJszhPCZ59ENHhhqNSJxB2rrKGTXjRvwWFE/4PWfCuc/V J2b8etWt3gXAcnUOHs7U1wJBzmzGuI8Lh6Kq9pksNi6m X-Google-Smtp-Source: AGHT+IFPb/F2MqElCTJh+Lvv3WT+OBDdKVX/5z+kAtQjFKDgwD11vGVkh7d9HglCG52aV5QocpeiqQ== X-Received: by 2002:a05:6358:ee88:b0:142:fd2b:d165 with SMTP id il8-20020a056358ee8800b00142fd2bd165mr2651776rwb.13.1697542647439; Tue, 17 Oct 2023 04:37:27 -0700 (PDT) Received: from localhost.localdomain ([171.216.79.181]) by smtp.gmail.com with ESMTPSA id x28-20020aa79a5c000000b00692c5b1a731sm1198647pfj.186.2023.10.17.04.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:37:26 -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: [PATCH 5/6] tests/migration: Introduce dirty-limit into guestperf Date: Tue, 17 Oct 2023 19:36:08 +0800 Message-Id: <1168bcbb38bc7457fcd9329f4da17b7e7976b4cc.1697502089.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::c34; envelope-from=yong.huang@smartx.com; helo=mail-oo1-xc34.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 --- 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 Tue Oct 17 11:36:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13425055 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 9E96ECDB474 for ; Tue, 17 Oct 2023 11:40:15 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qsiQB-0003WQ-Ga; Tue, 17 Oct 2023 07:39:35 -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 1qsiQ9-0003Jh-Ep for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:33 -0400 Received: from mail-oo1-xc2e.google.com ([2607:f8b0:4864:20::c2e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qsiQ7-00017r-Lj for qemu-devel@nongnu.org; Tue, 17 Oct 2023 07:39:33 -0400 Received: by mail-oo1-xc2e.google.com with SMTP id 006d021491bc7-57b635e3fd9so2819345eaf.3 for ; Tue, 17 Oct 2023 04:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1697542650; x=1698147450; 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=hMAM8qdrYGuxqIHYEejog6OmMQG8IBlM1A/6y2FwqWc=; b=blx3E0i4rS3LPGJ/fbKGjIbzcQE76g7slGd3z9BBptFvaK+8JXOZnh/sdmT8/kJXIE 8apP+9G/aBMWb6T9Wo3xFp8ohBJMhc8PjCniOYrUSfjzZhQHweeKZb/FM/Ho/edLe/8N Ad3bWsuj+mGj6A0srwQuu8TVk/M8iPmJFuI74281PUA7cD8orK3Wa9/WEhHWI6uq6uPK vvTJhD7yGYOux3VUX1ccSaZ5SBlax75aCcfh+vDB5zWYWrVkhJsaItF+dAQGJ4eM1gF3 d5pZq6KQWN6ozU6sJT3Yu+DO9zpZHkCOh62WtfxOgOXrD684FZt4QsD00ivsAMpn3EsN ECZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697542650; x=1698147450; 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=hMAM8qdrYGuxqIHYEejog6OmMQG8IBlM1A/6y2FwqWc=; b=PEoOeeh628Z05eCj9llVvOETqGrV6XvmziTtBSSIhZLdC2XjEj2QrrQD22BEhfJvl6 ZvtGFvNCr57R45lYuPSk0lk/mQ4nl5qdVBNE5Tr4wj3Qi+X8JQfl7T2ZhsC3IR/aQdhx 0k8enKrKgljZqcXLgUUm2+cxFEZ/U4Ym8kC3hbfQ3UIDpraITNMR0nQG0LV4uq8pJECi P2bsGdDAqv7NZKEscPjeCG3l4r3O+t8GCiYdDZ4uHa6wZ4jPrf/GJdGuPoZo6rLqp8I7 ZM5ftb7bNd8JMqiU1uJKKNabrE1UG0cZGxqSA/q+G+oikTEcvUQ1XNOO6o0EmvpbX7kJ cipA== X-Gm-Message-State: AOJu0YwsjUjj+4BQcxpRY20c33wQYGWR3MdFAoSD/Sz8qewj25ek4qo2 qONdmttNQGqO/oM3ERFOTMtAHRd66TWm2AQk1xMc6bUF X-Google-Smtp-Source: AGHT+IG0rxsOPnwJDL8anPIOAFahNe8Iz1nw4Kw5oViC8kSaGRJzTLiLMROjiIA+p4eRlP84/tV/rA== X-Received: by 2002:a05:6358:1e:b0:143:e3a:de5f with SMTP id 30-20020a056358001e00b001430e3ade5fmr1767956rww.26.1697542650040; Tue, 17 Oct 2023 04:37:30 -0700 (PDT) Received: from localhost.localdomain ([171.216.79.181]) by smtp.gmail.com with ESMTPSA id x28-20020aa79a5c000000b00692c5b1a731sm1198647pfj.186.2023.10.17.04.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 04:37:29 -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: [PATCH 6/6] docs/migration: Add the dirty limit section Date: Tue, 17 Oct 2023 19:36:09 +0800 Message-Id: <59985366f38053caac40c14d86b2a50bead944f6.1697502089.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::c2e; envelope-from=yong.huang@smartx.com; helo=mail-oo1-xc2e.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 --- docs/devel/migration.rst | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/docs/devel/migration.rst b/docs/devel/migration.rst index c3e1400c0c..1cbec22e2a 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 prepared 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_RULL 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_RULL 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 ========