From nobody Mon Feb 9 17:35:04 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; dmarc=fail(p=none dis=none) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1615898023; cv=none; d=zohomail.com; s=zohoarc; b=BJuJBHUJGH3bK0BKPpCoQunJnjjAU83xXZr14baPuEWdJc9dVrTGkXx5P1m5qlnGeyiic2Lx0ifbDL306MZFtixNITQOpRZfG02mIz+ffIJikcD/pClXPLhkaai7rU+1xM/h7KrAqVm+v9uZpxPcWEke/k3z8caFP6pTD4pdQ5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615898023; 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=ef5gkXaVqhBQCGcJ3kNqr/5iPS6ayuxaXe4Z0l9xJrc=; b=DL8m0slR3Y+zehWMapafTpDno70OpfPUd4tCwa4shSnK6HRA+Y7jAO/TSpfjgS7yz3ssPvbZVhQEZ/XU2M/stTZM5xek/tFlZXnbM+Xiru4QwgqkCb5PC5vdtKjDx9kS1LImb5aRry09Us7ibBWSiv+WW3pPltGG+TKzlvsEZSo= 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; dmarc=fail header.from= (p=none dis=none) header.from= 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 1615898023421906.9021153963332; Tue, 16 Mar 2021 05:33:43 -0700 (PDT) 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-294-cPlW2ySnM9Kl0XerZM0WUw-1; Tue, 16 Mar 2021 08:33:40 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 70BDC881D6C; Tue, 16 Mar 2021 12:33:34 +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 44FCE76C1D; Tue, 16 Mar 2021 12:33:34 +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 DF0E957DC4; Tue, 16 Mar 2021 12:33:33 +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 12GCXJEG030776 for ; Tue, 16 Mar 2021 08:33:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id DE8892166B44; Tue, 16 Mar 2021 12:33:19 +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 D972D2166BA2 for ; Tue, 16 Mar 2021 12:33:19 +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 C13D6100DE77 for ; Tue, 16 Mar 2021 12:33:19 +0000 (UTC) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-219-QD_NS56ENG6LB3SbDTJrBg-1; Tue, 16 Mar 2021 08:33:17 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4F0CM21RXrz905v; Tue, 16 Mar 2021 20:31:10 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Tue, 16 Mar 2021 20:32:53 +0800 X-MC-Unique: cPlW2ySnM9Kl0XerZM0WUw-1 X-MC-Unique: QD_NS56ENG6LB3SbDTJrBg-1 From: Hao Wang To: Subject: [PATCH v7 3/7] migration/dirtyrate: Introduce domdirtyrate-calc virsh api Date: Tue, 16 Mar 2021 20:32:47 +0800 Message-ID: <20210316123251.511485-4-wanghao232@huawei.com> In-Reply-To: <20210316123251.511485-1-wanghao232@huawei.com> References: <20210316123251.511485-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 12GCXJEG030776 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.11 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 | 58 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 9ff31a0160..367b4bddeb 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 information is available by calling +'domstats --dirtyrate'. + + domdisplay ---------- =20 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index f8f36ce361..7db88f700a 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -14402,6 +14402,58 @@ 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 " + "decide whether it's proper to be migrated out or not.\n" + "The calculated dirty rate information is available by " + "calling '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 =3D 1; /* the default value is 1 */ + bool ret =3D false; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (vshCommandOptInt(ctl, cmd, "seconds", &seconds) < 0) + goto cleanup; + + if (virDomainStartDirtyRateCalc(dom, seconds, 0) < 0) + goto cleanup; + + vshPrintExtra(ctl, _("Start to calculate domain's memory " + "dirty rate successfully.\n")); + ret =3D true; + + cleanup: + virshDomainFree(dom); + return ret; +} + + const vshCmdDef domManagementCmds[] =3D { {.name =3D "attach-device", .handler =3D cmdAttachDevice, @@ -15041,5 +15093,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