From nobody Wed Mar 12 17:15:17 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 1741097486895812.507101829476; Tue, 4 Mar 2025 06:11:26 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3F1C71579; Tue, 4 Mar 2025 09:11:26 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 43DA914F6; Tue, 4 Mar 2025 09:05:05 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 1A65B1434; Tue, 4 Mar 2025 09:05:01 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 0095C14E8 for ; Tue, 4 Mar 2025 09:04:38 -0500 (EST) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-QsKYJfFMM3aS5Hun3CIzGQ-1; Tue, 04 Mar 2025 09:04:37 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 376A61944CEE for ; Tue, 4 Mar 2025 14:04:36 +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 E557619560AB; Tue, 4 Mar 2025 14:04:34 +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=-1.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,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=1741097078; 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=rljVMqdO3EfMr7YDt08gqcCePQ20QMQBGhYByGMt4Ec=; b=Yt6tCmO3/CXZneQnayNjW3HtnAfc12Y1cvy7G3MtWbTeeIUJbmolkZuAxbEtL1ASax5IB9 cZWl70AtzEoviZViWRvlhJE5Pu0MaSwXWuZTyOo7xv+XmLBByRp+EeOdU+i/OAKaBd5TbN oBjJJNcdBhMHefUW5uDDZTAsOhDaRpE= X-MC-Unique: QsKYJfFMM3aS5Hun3CIzGQ-1 X-Mimecast-MFC-AGG-ID: QsKYJfFMM3aS5Hun3CIzGQ_1741097076 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 11/19] src: add constants for domain stats 'vcpu.' parameters Date: Tue, 4 Mar 2025 14:04:06 +0000 Message-ID: <20250304140414.3695867-12-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: tDpS_u2ZvWKqOfq-iKHJGFnbN2UB05F70W-xaC7XB04_1741097076 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: GKSNWXLEKCL6NWHRMUTBFCF4PXBVF7UO X-Message-ID-Hash: GKSNWXLEKCL6NWHRMUTBFCF4PXBVF7UO 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: 1741097489290019000 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 | 123 +++++++++++++++++++++++++++++++ src/libvirt-domain.c | 44 +++-------- src/qemu/qemu_driver.c | 44 +++++++---- 3 files changed, 166 insertions(+), 45 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 562bc6e17e..3f84cbce65 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -3066,6 +3066,129 @@ struct _virDomainStatsRecord { */ #define VIR_DOMAIN_STATS_BALLOON_HUGETLB_PGFAIL "balloon.hugetlb_pgfail" =20 + +/** + * VIR_DOMAIN_STATS_VCPU_CURRENT: + * + * Current number of online virtual CPUs as unsigned int. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_VCPU_CURRENT "vcpu.current" + +/** + * VIR_DOMAIN_STATS_VCPU_MAXIMUM: + * + * maximum number of online virtual CPUs as unsigned int. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_VCPU_MAXIMUM "vcpu.maximum" + +/** + * VIR_DOMAIN_STATS_VCPU_PREFIX: + * + * The parameter name prefix to access each vCPU entry. Concatenate the + * prefix, the entry number formatted as an unsigned integer and one of the + * vCPU suffix parameters to form a complete parameter name. + * + * Due to VCPU hotplug, the array could be sparse. The actual number of + * entries present corresponds to VIR_DOMAIN_STATS_VCPU_CURRENT, while the + * array size will never exceed VIR_DOMAIN_STATS_VCPU_MAXIMUM. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_VCPU_PREFIX "vcpu." + +/** + * VIR_DOMAIN_STATS_VCPU_SUFFIX_STATE: + * + * State of the virtual CPU , as int from virVcpuState enum. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_VCPU_SUFFIX_STATE ".state" + +/** + * VIR_DOMAIN_STATS_VCPU_SUFFIX_TIME: + * + * Virtual cpu time spent by virtual CPU as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_VCPU_SUFFIX_TIME ".time" + +/** + * VIR_DOMAIN_STATS_VCPU_SUFFIX_WAIT: + * + * Time the vCPU wants to run, but the host scheduler has something else + * running ahead of it as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_VCPU_SUFFIX_WAIT ".wait" + +/** + * VIR_DOMAIN_STATS_VCPU_SUFFIX_HALTED: + * + * Virtual CPU is halted as a boolean, may indicate the processor is idle = or + * even disabled, depending on the architecture. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_VCPU_SUFFIX_HALTED ".halted" + +/** + * VIR_DOMAIN_STATS_VCPU_SUFFIX_DELAY: + * + * Time the vCPU thread was enqueued by the host scheduler, but was waitin= g in + * the queue instead of running. Exposed to the VM as a steal time. In + * nanoseconds as unsigned long long. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_VCPU_SUFFIX_DELAY ".delay" + + +/** + * VIR_DOMAIN_STATS_CUSTOM_SUFFIX_TYPE_CUR: + * + * Hypervisor specific custom data type for current instant value + * + * The complete parameter name is formed by concatenating the field prefix, + * the array index formatted as an unsigned integer, a hypervisor specific + * parameter name, and this data type suffix. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_CUSTOM_SUFFIX_TYPE_CUR ".cur" + +/** + * VIR_DOMAIN_STATS_CUSTOM_SUFFIX_TYPE_SUM: + * + * Hypervisor specific custom data type for current instant value + * + * The complete parameter name is formed by concatenating the field prefix, + * the array index formatted as an unsigned integer, a hypervisor specific + * parameter name, and this data type suffix. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_CUSTOM_SUFFIX_TYPE_SUM ".sum" + +/** + * VIR_DOMAIN_STATS_CUSTOM_SUFFIX_TYPE_MAX: + * + * Hypervisor specific custom data type for peak value. + * + * The complete parameter name is formed by concatenating the field prefix, + * the array index formatted as an unsigned integer, a hypervisor specific + * parameter name, and this data type suffix. + * + * Since: 11.2.0 + */ +#define VIR_DOMAIN_STATS_CUSTOM_SUFFIX_TYPE_MAX ".max" + /** * virDomainStatsTypes: * diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 6c86ad566f..78bc053151 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -12253,43 +12253,23 @@ virConnectGetDomainCapabilities(virConnectPtr con= n, * * VIR_DOMAIN_STATS_VCPU: * Return virtual CPU statistics. - * Due to VCPU hotplug, the vcpu..* array could be sparse. - * The actual size of the array corresponds to "vcpu.current". - * The array size will never exceed "vcpu.maximum". - * The typed parameter keys are in this format: + * The VIR_DOMAIN_STATS_VCPU_* constants define the known typed + * parameter keys. * - * "vcpu.current" - current number of online virtual CPUs as unsigned = int. - * "vcpu.maximum" - maximum number of online virtual CPUs as unsigned = int. - * "vcpu..state" - state of the virtual CPU , as int - * from virVcpuState enum. - * "vcpu..time" - virtual cpu time spent by virtual CPU - * as unsigned long long. - * "vcpu..wait" - time the vCPU wants to run, but the host - * scheduler has something else running ahead of i= t. - * "vcpu..halted" - virtual CPU is halted, may indicate the - * processor is idle or even disabled, depending - * on the architecture) - * "vcpu..delay" - time the vCPU thread was enqueued by the - * host scheduler, but was waiting in the queue - * instead of running. Exposed to the VM as a ste= al - * time. (in nanoseconds) - * - * This group of statistics also reports additional hypervisor-originat= ing - * per-vCPU stats. The hypervisor-specific statistics in this group hav= e the - * following naming scheme: + * This group of statistics also reports additional hypervisor-origina= ting + * per-vCPU stats. The hypervisor-specific statistics in this group ha= ve the + * following naming scheme: * * "vcpu..$NAME.$TYPE" * - * $NAME - name of the statistics field provided by the hypervisor + * Where $NAME is an arbitrary choice of the hypervisor driver, for + * which no API constants are defined. + * The $TYPE values are defined by VIR_DOMAIN_STATS_CUSTOM_TYPE_* + * constants. * - * $TYPE - Type of the value. The following types are returned: - * 'cur' - current instant value - * 'sum' - aggregate value - * 'max' - peak value - * - * The returned value may be either an unsigned long long or a boolea= n. - * Meaning is hypervisor specific. Please see the disclaimer for the - * VIR_DOMAIN_STATS_VM group below. + * The returned value may be either an unsigned long long or a boolean. + * Meaning is hypervisor specific. Please see the disclaimer for the + * VIR_DOMAIN_STATS_VM group below. * * VIR_DOMAIN_STATS_INTERFACE: * Return network interface statistics (from domain point of view). diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index fb6e3ced73..2e652e68e9 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17065,14 +17065,15 @@ qemuDomainAddStatsFromHashTable(GHashTable *stats, =20 switch (data->type) { case QEMU_MONITOR_QUERY_STATS_TYPE_CUMULATIVE: - type =3D "sum"; + type =3D VIR_DOMAIN_STATS_CUSTOM_SUFFIX_TYPE_SUM; break; + case QEMU_MONITOR_QUERY_STATS_TYPE_INSTANT: - type =3D "cur"; + type =3D VIR_DOMAIN_STATS_CUSTOM_SUFFIX_TYPE_CUR; break; =20 case QEMU_MONITOR_QUERY_STATS_TYPE_PEAK: - type =3D "max"; + type =3D VIR_DOMAIN_STATS_CUSTOM_SUFFIX_TYPE_MAX; break; =20 case QEMU_MONITOR_QUERY_STATS_TYPE_LOG2_HISTOGRAM: @@ -17087,14 +17088,14 @@ qemuDomainAddStatsFromHashTable(GHashTable *stats, if (virJSONValueGetBoolean(value, &stat) < 0) continue; =20 - virTypedParamListAddBoolean(params, stat, "%s.%s.%s", prefix, = key, type); + virTypedParamListAddBoolean(params, stat, "%s.%s%s", prefix, k= ey, type); } else { unsigned long long stat; =20 if (virJSONValueGetNumberUlong(value, &stat) < 0) continue; =20 - virTypedParamListAddULLong(params, stat, "%s.%s.%s", prefix, k= ey, type); + virTypedParamListAddULLong(params, stat, "%s.%s%s", prefix, ke= y, type); } } } @@ -17115,8 +17116,10 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNU= C_UNUSED, qemuDomainObjPrivate *priv =3D dom->privateData; g_autoptr(virJSONValue) queried_stats =3D NULL; =20 - virTypedParamListAddUInt(params, virDomainDefGetVcpus(dom->def), "vcpu= .current"); - virTypedParamListAddUInt(params, virDomainDefGetVcpusMax(dom->def), "v= cpu.maximum"); + virTypedParamListAddUInt(params, virDomainDefGetVcpus(dom->def), + VIR_DOMAIN_STATS_VCPU_CURRENT); + virTypedParamListAddUInt(params, virDomainDefGetVcpusMax(dom->def), + VIR_DOMAIN_STATS_VCPU_MAXIMUM); =20 cpuinfo =3D g_new0(virVcpuInfo, virDomainDefGetVcpus(dom->def)); cpuwait =3D g_new0(unsigned long long, virDomainDefGetVcpus(dom->def)); @@ -17147,17 +17150,30 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GN= UC_UNUSED, for (i =3D 0; i < virDomainDefGetVcpus(dom->def); i++) { virJSONValue *stat_obj =3D NULL; g_autoptr(GHashTable) stats =3D NULL; - g_autofree char *prefix =3D g_strdup_printf("vcpu.%u", cpuinfo[i].= number); + g_autofree char *prefix =3D g_strdup_printf( + VIR_DOMAIN_STATS_VCPU_PREFIX "%u", cpuinfo[i].number); =20 - virTypedParamListAddInt(params, cpuinfo[i].state, "vcpu.%u.state",= cpuinfo[i].number); + virTypedParamListAddInt(params, cpuinfo[i].state, + VIR_DOMAIN_STATS_VCPU_PREFIX "%u" + VIR_DOMAIN_STATS_VCPU_SUFFIX_STATE, + cpuinfo[i].number); =20 /* stats below are available only if the VM is alive */ if (!virDomainObjIsActive(dom)) continue; =20 - virTypedParamListAddULLong(params, cpuinfo[i].cpuTime, "vcpu.%u.ti= me", cpuinfo[i].number); - virTypedParamListAddULLong(params, cpuwait[i], "vcpu.%u.wait", cpu= info[i].number); - virTypedParamListAddULLong(params, cpudelay[i], "vcpu.%u.delay", c= puinfo[i].number); + virTypedParamListAddULLong(params, cpuinfo[i].cpuTime, + VIR_DOMAIN_STATS_VCPU_PREFIX "%u" + VIR_DOMAIN_STATS_VCPU_SUFFIX_TIME, + cpuinfo[i].number); + virTypedParamListAddULLong(params, cpuwait[i], + VIR_DOMAIN_STATS_VCPU_PREFIX "%u" + VIR_DOMAIN_STATS_VCPU_SUFFIX_WAIT, + cpuinfo[i].number); + virTypedParamListAddULLong(params, cpudelay[i], + VIR_DOMAIN_STATS_VCPU_PREFIX "%u" + VIR_DOMAIN_STATS_VCPU_SUFFIX_DELAY, + cpuinfo[i].number); =20 /* state below is extracted from the individual vcpu structs */ if (!(vcpu =3D virDomainDefGetVcpu(dom->def, cpuinfo[i].number))) @@ -17167,7 +17183,9 @@ qemuDomainGetStatsVcpu(virQEMUDriver *driver G_GNUC= _UNUSED, =20 if (vcpupriv->halted !=3D VIR_TRISTATE_BOOL_ABSENT) { virTypedParamListAddBoolean(params, vcpupriv->halted =3D=3D VI= R_TRISTATE_BOOL_YES, - "vcpu.%u.halted", cpuinfo[i].numbe= r); + VIR_DOMAIN_STATS_VCPU_PREFIX "%u" + VIR_DOMAIN_STATS_VCPU_SUFFIX_HALTE= D, + cpuinfo[i].number); } =20 if (!queried_stats) --=20 2.48.1