From nobody Mon Feb 9 20:37:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644971383811834.6752008153519; Tue, 15 Feb 2022 16:29:43 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-546-wCFB6khUPVWePIKAJti4YQ-1; Tue, 15 Feb 2022 19:29:41 -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 AA60C1091DA4; Wed, 16 Feb 2022 00:29:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8AF6D4EC66; Wed, 16 Feb 2022 00:29:35 +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 5BACA18045C5; Wed, 16 Feb 2022 00:29:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21G0TPcN024676 for ; Tue, 15 Feb 2022 19:29:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 034D74010A13; Wed, 16 Feb 2022 00:29:25 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast08.extmail.prod.ext.rdu2.redhat.com [10.11.55.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E96F84010A12 for ; Wed, 16 Feb 2022 00:29:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CAFDE381078B for ; Wed, 16 Feb 2022 00:29:24 +0000 (UTC) Received: from chinatelecom.cn (prt-mail.chinatelecom.cn [42.123.76.227]) by relay.mimecast.com with ESMTP id us-mta-17-vcDFImhtP1q-M05wUI9mJA-3; Tue, 15 Feb 2022 19:29:22 -0500 Received: from clientip-171.223.98.212 (unknown [172.18.0.188]) by chinatelecom.cn (HERMES) with SMTP id 526E928008E; Wed, 16 Feb 2022 08:29:20 +0800 (CST) Received: from ([172.18.0.188]) by app0023 with ESMTP id 1e275b78d09a41d3827d35685e9599ad for libvir-list@redhat.com; Wed, 16 Feb 2022 08:29:21 CST X-MC-Unique: wCFB6khUPVWePIKAJti4YQ-1 X-MC-Unique: vcDFImhtP1q-M05wUI9mJA-3 HMM_SOURCE_IP: 172.18.0.188:46950.167132848 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +huangy81@chinatelecom.cn X-Transaction-ID: 1e275b78d09a41d3827d35685e9599ad X-Real-From: huangy81@chinatelecom.cn X-Receive-IP: 172.18.0.188 X-MEDUSA-Status: 0 From: huangy81@chinatelecom.cn To: libvir-list@redhat.com Subject: [PATCH v5 8/9] virsh: Add mode option to domdirtyrate-calc virsh api Date: Wed, 16 Feb 2022 08:29:04 +0800 Message-Id: <55b42309b0c1052d84ff26fa1915cdf81883bc5b.1644971072.git.huangy81@chinatelecom.cn> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 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-Mimecast-Spam-Signature: yes X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 21G0TPcN024676 X-loop: libvir-list@redhat.com Cc: huangy81@chinatelecom.cn 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1644971385900100003 From: Hyman Huang(=E9=BB=84=E5=8B=87) Extend domdirtyrate-calc virsh api with mode option, either of these three options "page-sampling,dirty-bitmap,dirty-ring" can be specified when calculating dirty page rate. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- docs/manpages/virsh.rst | 7 +++++-- src/libvirt-domain.c | 12 +++++++++++- tools/virsh-completer-domain.c | 17 +++++++++++++++++ tools/virsh-completer-domain.h | 4 ++++ tools/virsh-domain.c | 42 ++++++++++++++++++++++++++++++++++++++= +++- tools/virsh-domain.h | 9 +++++++++ 6 files changed, 87 insertions(+), 4 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 429879d..00d21a1 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1717,13 +1717,16 @@ domdirtyrate-calc :: =20 domdirtyrate-calc [--seconds ] + --mode=3D[page-sampling | dirty-bitmap | dirty-ring] =20 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'. +if missing. These three *page-sampling, dirty-bitmap, dirty-ring* modes +are mutually exclusive and alternative when specify calculation mode, +*page-sampling* is the default mode if missing. The calculated dirty +rate information is available by calling 'domstats --dirtyrate'. =20 =20 domdisplay diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index f24d072..f70eff3 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -13313,7 +13313,7 @@ virDomainGetMessages(virDomainPtr domain, * virDomainStartDirtyRateCalc: * @domain: a domain object * @seconds: specified calculating time in seconds - * @flags: extra flags; not used yet, so callers should always pass 0 + * @flags: bitwise-OR of supported virDomainDirtyRateCalcFlags * * Calculate the current domain's memory dirty rate in next @seconds. * The calculated dirty rate information is available by calling @@ -13337,6 +13337,16 @@ virDomainStartDirtyRateCalc(virDomainPtr domain, =20 virCheckReadOnlyGoto(conn->flags, error); =20 + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_DIRTYRATE_MODE_PAGE_SAMPLING, + VIR_DOMAIN_DIRTYRATE_MODE_DIRTY_BITMAP, + error); + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_DIRTYRATE_MODE_PAGE_SAMPLING, + VIR_DOMAIN_DIRTYRATE_MODE_DIRTY_RING, + error); + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_DIRTYRATE_MODE_DIRTY_BITMAP, + VIR_DOMAIN_DIRTYRATE_MODE_DIRTY_RING, + error); + if (conn->driver->domainStartDirtyRateCalc) { int ret; ret =3D conn->driver->domainStartDirtyRateCalc(domain, seconds, fl= ags); diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index b4e744c..1c2df56 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -1150,3 +1150,20 @@ virshDomainNumatuneModeCompleter(vshControl *ctl G_G= NUC_UNUSED, =20 return ret; } + + +char ** +virshDomainDirtyRateCalcModeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + const char *modes[] =3D {"page-sampling", "dirty-bitmap", "dirty-ring"= , NULL}; + const char *mode =3D NULL; + + virCheckFlags(0, NULL); + + if (vshCommandOptStringQuiet(ctl, cmd, "mode", &mode) < 0) + return NULL; + + return virshCommaStringListComplete(mode, modes); +} diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 94bb3b5..044c675 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -186,3 +186,7 @@ char ** virshDomainNumatuneModeCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); +char ** +virshDomainDirtyRateCalcModeCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 4ff531f..1902eb9 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -14484,14 +14484,28 @@ static const vshCmdOptDef opts_domdirtyrate_calc[= ] =3D { .help =3D N_("calculate memory dirty rate within specified seconds, " "the supported value range from 1 to 60, default to 1.") }, + {.name =3D "mode", + .type =3D VSH_OT_STRING, + .completer =3D virshDomainDirtyRateCalcModeCompleter, + .help =3D N_("dirty page rate calculation mode, either of these 3 opt= ions " + "'page-sampling,dirty-bitmap,dirty-ring' can be specified.= ") + }, {.name =3D NULL} }; =20 +VIR_ENUM_IMPL(virshDomainDirtyRateCalcMode, + VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_LAST, + "page-sampling", + "dirty-bitmap", + "dirty-ring"); + static bool cmdDomDirtyRateCalc(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; int seconds =3D 1; /* the default value is 1 */ + const char *modestr =3D NULL; + unsigned int flags =3D 0; =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -14499,7 +14513,33 @@ cmdDomDirtyRateCalc(vshControl *ctl, const vshCmd = *cmd) if (vshCommandOptInt(ctl, cmd, "seconds", &seconds) < 0) return false; =20 - if (virDomainStartDirtyRateCalc(dom, seconds, 0) < 0) + if (vshCommandOptStringReq(ctl, cmd, "mode", &modestr) < 0) + return false; + + if (modestr) { + int mode =3D virshDomainDirtyRateCalcModeTypeFromString(modestr); + + if (mode < 0) { + vshError(ctl, _("Unknown calculation mode '%s'"), modestr); + return false; + } + + switch ((virshDomainDirtyRateCalcMode) mode) { + case VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_PAGE_SAMPLING: + flags |=3D VIR_DOMAIN_DIRTYRATE_MODE_PAGE_SAMPLING; + break; + case VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_DIRTY_BITMAP: + flags |=3D VIR_DOMAIN_DIRTYRATE_MODE_DIRTY_BITMAP;; + break; + case VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_DIRTY_RING: + flags |=3D VIR_DOMAIN_DIRTYRATE_MODE_DIRTY_RING;; + break; + case VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_LAST: + break; + } + } + + if (virDomainStartDirtyRateCalc(dom, seconds, flags) < 0) return false; =20 vshPrintExtra(ctl, _("Start to calculate domain's memory " diff --git a/tools/virsh-domain.h b/tools/virsh-domain.h index cf5ce28..6a94438 100644 --- a/tools/virsh-domain.h +++ b/tools/virsh-domain.h @@ -46,6 +46,15 @@ typedef enum { =20 VIR_ENUM_DECL(virshDomainInterfaceSourceMode); =20 +typedef enum { + VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_PAGE_SAMPLING, + VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_DIRTY_BITMAP, + VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_DIRTY_RING, + VIRSH_DOMAIN_DIRTYRATE_CALC_MODE_LAST, +} virshDomainDirtyRateCalcMode; + +VIR_ENUM_DECL(virshDomainDirtyRateCalcMode); + extern const vshCmdDef domManagementCmds[]; =20 VIR_ENUM_DECL(virshDomainProcessSignal); --=20 1.8.3.1