From nobody Mon Feb 9 21:22:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1614328547; cv=none; d=zohomail.com; s=zohoarc; b=cgntAkLinY3qIeS24aede2CQLMlOrZTulvz9HSEjaBRWvYq6ipWLGtY4wdYGMyeW4XIwMigYEBJulm76C6FE2X5m4xPzeYg0F+9rOQkKiIYgfaPH3CacFOGf77QWUCzybu6tkFZRtJQ6Y51kOm09Y5mPYhJUgW2OzNkPkAT2ZI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614328547; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZXPJdV3hKuhdcJawkdnZfhtDworYjynZxWvT20DzbCQ=; b=GUIqOMzozSYzFABYTjlNSz3JakIShvZpEeQzrNWLUQujRnWdn9G8DBV8T1SiPmwdbjIUODnc6KwhIyqmwUhWt33GCV2LrVRsrhtO0vOzjKCzk0mZUChxZHTn0VgnZmTF7dACN4wPlij5TfPBfnqsdP4aLHRp2yQosiBmi13KUuA= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1614328547150838.8383075367738; Fri, 26 Feb 2021 00:35:47 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-378-6BG94miqNhuG57JFioy2Mg-1; Fri, 26 Feb 2021 03:35:43 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 111D980196C; Fri, 26 Feb 2021 08:35:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 97F0061F55; Fri, 26 Feb 2021 08:35:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 13E574E58D; Fri, 26 Feb 2021 08:35:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11Q8ZTtb002099 for ; Fri, 26 Feb 2021 03:35:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1ECAF20F4721; Fri, 26 Feb 2021 08:35:29 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 195E02166B27 for ; Fri, 26 Feb 2021 08:35:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7785A1022F0E for ; Fri, 26 Feb 2021 08:35:26 +0000 (UTC) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-35-ENh4nRJkOmWu1QkhdyUATw-1; Fri, 26 Feb 2021 03:35:23 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Dn2xL4Sv4zjS3L; Fri, 26 Feb 2021 16:33:42 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.498.0; Fri, 26 Feb 2021 16:35:13 +0800 X-MC-Unique: 6BG94miqNhuG57JFioy2Mg-1 X-MC-Unique: ENh4nRJkOmWu1QkhdyUATw-1 From: Hao Wang To: Subject: [PATCH v6 3/5] migration/dirtyrate: Introduce domdirtyrate-calc virsh api Date: Fri, 26 Feb 2021 16:35:08 +0800 Message-ID: <20210226083510.1506318-4-wanghao232@huawei.com> In-Reply-To: <20210226083510.1506318-1-wanghao232@huawei.com> References: <20210226083510.1506318-1-wanghao232@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 11Q8ZTtb002099 X-loop: libvir-list@redhat.com Cc: yubihong@huawei.com, zhengchuan@huawei.com, pkrempa@redhat.com, zhang.zhanghailiang@huawei.com, mprivozn@redhat.com, danielhb413@gmail.com, xiexiangyou@huawei.com, alex.chen@huawei.com, wanghao232@huawei.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Introduce domdirtyrate-calc virsh api to start calculating domain's memory dirty rate: # virsh domdirtyrate-calc [--seconds ] Signed-off-by: Hao Wang --- docs/manpages/virsh.rst | 17 +++++++++++ tools/virsh-domain.c | 63 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 8a4328faa0..417ea444f4 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1704,6 +1704,23 @@ states other than "ok" or "error" the command also p= rints number of seconds elapsed since the control interface entered its current state. =20 =20 +domdirtyrate-calc +----------------- + +**Syntax:** + +:: + + domdirtyrate-calc [--seconds ] + +Calculate an active domain's memory dirty rate which may be expected by +user in order to decide whether it's proper to be migrated out or not. +The ``seconds`` parameter can be used to calculate dirty rate in a +specific time which allows 60s at most now and would be default to 1s +if missing. The calculated dirty rate infomation is available by calling +'domstats --dirtyrate'. + + domdisplay ---------- =20 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index df33467646..ccb5d61a25 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -14412,6 +14412,63 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *c= md) } =20 =20 +/* + * "domdirtyrate" command + */ +static const vshCmdInfo info_domdirtyrate_calc[] =3D { + {.name =3D "help", + .data =3D N_("Calculate a vm's memory dirty rate") + }, + {.name =3D "desc", + .data =3D N_("Calculate memory dirty rate of a domain in order to dec= ide whether " + "it's proper to be migrated out or not.\n" + "The calculated dirty rate infomation is available by call= ing " + "'domstats --dirtyrate'.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_domdirtyrate_calc[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "seconds", + .type =3D VSH_OT_INT, + .help =3D N_("calculate memory dirty rate within specified seconds, " + "the supported value range from 1 to 60, default to 1.") + }, + {.name =3D NULL} +}; + +static bool +cmdDomDirtyRateCalc(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + int seconds; + int rc; + bool ret =3D false; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + rc =3D vshCommandOptInt(ctl, cmd, "seconds", &seconds); + if (rc < 0) + goto cleanup; + + /* if no inputted seconds, default to 1s */ + if (!rc) + seconds =3D 1; + + if (virDomainStartDirtyRateCalc(dom, seconds, 0) < 0) + goto cleanup; + + vshPrint(ctl, _("Start to calculate domain's memory dirty rate success= fully.\n")); + ret =3D true; + + cleanup: + virshDomainFree(dom); + return ret; +} + + const vshCmdDef domManagementCmds[] =3D { {.name =3D "attach-device", .handler =3D cmdAttachDevice, @@ -15051,5 +15108,11 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_guestinfo, .flags =3D 0 }, + {.name =3D "domdirtyrate-calc", + .handler =3D cmdDomDirtyRateCalc, + .opts =3D opts_domdirtyrate_calc, + .info =3D info_domdirtyrate_calc, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.23.0