From nobody Wed Mar 12 17:13:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1741097550806877.8671417825082; Tue, 4 Mar 2025 06:12:30 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 333AA15AE; Tue, 4 Mar 2025 09:12:30 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C0D991557; Tue, 4 Mar 2025 09:05:09 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9572C1456; Tue, 4 Mar 2025 09:05:05 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id EB62F13BE for ; Tue, 4 Mar 2025 09:04:41 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-658-SiVc-oiGO0O3UcT4MKC5kQ-1; Tue, 04 Mar 2025 09:04:35 -0500 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7A49C180098C for ; Tue, 4 Mar 2025 14:04:34 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.210]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6AE7B19560B9; Tue, 4 Mar 2025 14:04:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741097081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0K7zLU1Mh/6CPVHq+bHHS/kBY8yPfLeXyVW/c2WnpLY=; b=Gkabh2hEab/VP+sjDJsFYb2IP9CeHMKXM5x2VBd5t14kicZ8CGT+J0dsnt8t7DlXLm02MH 0KNuVhKyiGTxZlRKq5ozjYWsJTXko+oylOMz+YBJBqVVGh7rUNjQC9EmZVi9HHMG+yAfSz i2ggk6gpWMwF9zw3SuLXVDnF71o16o0= X-MC-Unique: SiVc-oiGO0O3UcT4MKC5kQ-1 X-Mimecast-MFC-AGG-ID: SiVc-oiGO0O3UcT4MKC5kQ_1741097074 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: devel@lists.libvirt.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH 10/19] src: add constants for domain stats 'balloon.' parameters Date: Tue, 4 Mar 2025 14:04:05 +0000 Message-ID: <20250304140414.3695867-11-berrange@redhat.com> In-Reply-To: <20250304140414.3695867-1-berrange@redhat.com> References: <20250304140414.3695867-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 4RTKpuWBDeQCq6OWeTyoeSzl8ecEsJT_LGpFhp4hgfU_1741097074 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 3BSSUJQVHDLSF6BWAZ7JEZY2KCXL6KS5 X-Message-ID-Hash: 3BSSUJQVHDLSF6BWAZ7JEZY2KCXL6KS5 X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1741097552902019000 Content-Type: text/plain; charset="utf-8" Contrary to most APIs returning typed parameters, there are no constants defined for the domain stats data keys. This is was because many of the keys needs to be dynamically constructed using one or more array index values. It is possible to define constants while still supporting dynamic array indexes by simply defining the prefixes and suffixes as constants. The consuming code can then combine the constants with array index value. With this approach, it is practical to add constants for the domain stats API keys. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Krempa --- include/libvirt/libvirt-domain.h | 136 +++++++++++++++++++++++++++++++ src/libvirt-domain.c | 36 +------- src/qemu/qemu_driver.c | 34 ++++---- 3 files changed, 156 insertions(+), 50 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 7e9f998f2f..562bc6e17e 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2930,6 +2930,142 @@ struct _virDomainStatsRecord { */ #define VIR_DOMAIN_STATS_CPU_CACHE_MONITOR_SUFFIX_BANK_SUFFIX_BYTES ".byte= s" =20 + +/** + * VIR_DOMAIN_STATS_BALLOON_CURRENT: + * + * The memory in kiB currently used as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_CURRENT "balloon.current" + +/** + * VIR_DOMAIN_STATS_BALLOON_MAXIMUM: + * + * The maximum memory in kiB allowed as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_MAXIMUM "balloon.maximum" + +/** + * VIR_DOMAIN_STATS_BALLOON_SWAP_IN: + * + * The amount of data read from swap space (in KiB) as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_SWAP_IN "balloon.swap_in" + +/** + * VIR_DOMAIN_STATS_BALLOON_SWAP_OUT: + * + * The amount of memory written out to swap space (in KiB) as unsigned long + * long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_SWAP_OUT "balloon.swap_out" + +/** + * VIR_DOMAIN_STATS_BALLOON_MAJOR_FAULT: + * + * The number of page faults when disk IO was required as unsigned long lo= ng. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_MAJOR_FAULT "balloon.major_fault" + +/** + * VIR_DOMAIN_STATS_BALLOON_MINOR_FAULT: + * + * The number of other page faults as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_MINOR_FAULT "balloon.minor_fault" + +/** + * VIR_DOMAIN_STATS_BALLOON_UNUSED: + * + * The amount of memory left unused by the system (in KiB) as unsigned long + * long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_UNUSED "balloon.unused" + +/** + * VIR_DOMAIN_STATS_BALLOON_AVAILABLE: + * + * The amount of usable memory as seen by the domain (in KiB) as unsigned = long + * long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_AVAILABLE "balloon.available" + +/** + * VIR_DOMAIN_STATS_BALLOON_RSS: + * + * Resident Set Size of running domain's process (in KiB) as unsigned long + * long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_RSS "balloon.rss" + +/** + * VIR_DOMAIN_STATS_BALLOON_USABLE: + * + * The amount of memory which can be reclaimed by balloon without causing = host + * swapping (in KiB) as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_USABLE "balloon.usable" + +/** + * VIR_DOMAIN_STATS_BALLOON_LAST_UPDATE: + * + * Timestamp of the last update of statistics (in seconds) as unsigned long + * long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_LAST_UPDATE "balloon.last-update" + +/** + * VIR_DOMAIN_STATS_BALLOON_DISK_CACHES: + * + * The amount of memory that can be reclaimed without additional I/O, + * typically disk (in KiB) as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_DISK_CACHES "balloon.disk_caches" + +/** + * VIR_DOMAIN_STATS_BALLOON_HUGETLB_PGALLOC: + * + * The number of successful huge page allocations from inside the domain v= ia + * virtio balloon as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_HUGETLB_PGALLOC "balloon.hugetlb_pgalloc" + +/** + * VIR_DOMAIN_STATS_BALLOON_HUGETLB_PGFAIL: + * + * The number of failed huge page allocations from inside the domain via + * virtio balloon as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_BALLOON_HUGETLB_PGFAIL "balloon.hugetlb_pgfail" + /** * virDomainStatsTypes: * diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 6b80206f25..6c86ad566f 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -12248,40 +12248,8 @@ virConnectGetDomainCapabilities(virConnectPtr conn, * * VIR_DOMAIN_STATS_BALLOON: * Return memory balloon device information. - * The typed parameter keys are in this format: - * - * "balloon.current" - the memory in kiB currently used - * as unsigned long long. - * "balloon.maximum" - the maximum memory in kiB allowed - * as unsigned long long. - * "balloon.swap_in" - the amount of data read from swap space (in KiB) - * as unsigned long long - * "balloon.swap_out" - the amount of memory written out to swap space - * (in KiB) as unsigned long long - * "balloon.major_fault" - the number of page faults when disk IO was - * required as unsigned long long - * "balloon.minor_fault" - the number of other page faults - * as unsigned long long - * "balloon.unused" - the amount of memory left unused by the system - * (in KiB) as unsigned long long - * "balloon.available" - the amount of usable memory as seen by the do= main - * (in KiB) as unsigned long long - * "balloon.rss" - Resident Set Size of running domain's process - * (in KiB) as unsigned long long - * "balloon.usable" - the amount of memory which can be reclaimed by b= alloon - * without causing host swapping (in KiB) - * as unsigned long long - * "balloon.last-update" - timestamp of the last update of statistics - * (in seconds) as unsigned long long - * "balloon.disk_caches" - the amount of memory that can be reclaimed - * without additional I/O, typically disk (in = KiB) - * as unsigned long long - * "balloon.hugetlb_pgalloc" - the number of successful huge page allo= cations - * from inside the domain via virtio ballo= on - * as unsigned long long - * "balloon.hugetlb_pgfail" - the number of failed huge page allocatio= ns - * from inside the domain via virtio balloon - * as unsigned long long + * The VIR_DOMAIN_STATS_BALLOON_* constants define the known typed + * parameter keys. * * VIR_DOMAIN_STATS_VCPU: * Return virtual CPU statistics. diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ff149a46ef..fb6e3ced73 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17005,8 +17005,10 @@ qemuDomainGetStatsBalloon(virQEMUDriver *driver G_= GNUC_UNUSED, cur_balloon =3D dom->def->mem.cur_balloon; } =20 - virTypedParamListAddULLong(params, cur_balloon, "balloon.current"); - virTypedParamListAddULLong(params, virDomainDefGetMemoryTotal(dom->def= ), "balloon.maximum"); + virTypedParamListAddULLong(params, cur_balloon, + VIR_DOMAIN_STATS_BALLOON_CURRENT); + virTypedParamListAddULLong(params, virDomainDefGetMemoryTotal(dom->def= ), + VIR_DOMAIN_STATS_BALLOON_MAXIMUM); =20 if (!HAVE_JOB(privflags) || !virDomainObjIsActive(dom)) return; @@ -17016,23 +17018,23 @@ qemuDomainGetStatsBalloon(virQEMUDriver *driver G= _GNUC_UNUSED, if (nr_stats < 0) return; =20 -#define STORE_MEM_RECORD(TAG, NAME) \ +#define STORE_MEM_RECORD(TAG) \ if (stats[i].tag =3D=3D VIR_DOMAIN_MEMORY_STAT_ ##TAG) \ - virTypedParamListAddULLong(params, stats[i].val, "balloon." NAME); + virTypedParamListAddULLong(params, stats[i].val, VIR_DOMAIN_STATS= _BALLOON_ ##TAG) =20 for (i =3D 0; i < nr_stats; i++) { - STORE_MEM_RECORD(SWAP_IN, "swap_in") - STORE_MEM_RECORD(SWAP_OUT, "swap_out") - STORE_MEM_RECORD(MAJOR_FAULT, "major_fault") - STORE_MEM_RECORD(MINOR_FAULT, "minor_fault") - STORE_MEM_RECORD(UNUSED, "unused") - STORE_MEM_RECORD(AVAILABLE, "available") - STORE_MEM_RECORD(RSS, "rss") - STORE_MEM_RECORD(LAST_UPDATE, "last-update") - STORE_MEM_RECORD(USABLE, "usable") - STORE_MEM_RECORD(DISK_CACHES, "disk_caches") - STORE_MEM_RECORD(HUGETLB_PGALLOC, "hugetlb_pgalloc") - STORE_MEM_RECORD(HUGETLB_PGFAIL, "hugetlb_pgfail") + STORE_MEM_RECORD(SWAP_IN); + STORE_MEM_RECORD(SWAP_OUT); + STORE_MEM_RECORD(MAJOR_FAULT); + STORE_MEM_RECORD(MINOR_FAULT); + STORE_MEM_RECORD(UNUSED); + STORE_MEM_RECORD(AVAILABLE); + STORE_MEM_RECORD(RSS); + STORE_MEM_RECORD(LAST_UPDATE); + STORE_MEM_RECORD(USABLE); + STORE_MEM_RECORD(DISK_CACHES); + STORE_MEM_RECORD(HUGETLB_PGALLOC); + STORE_MEM_RECORD(HUGETLB_PGFAIL); } =20 #undef STORE_MEM_RECORD --=20 2.48.1