From nobody Wed Mar 12 17:44:06 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 1741703565302879.4215906431313; Tue, 11 Mar 2025 07:32:45 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 5062196D; Tue, 11 Mar 2025 10:32:44 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5E4E71DDD; Tue, 11 Mar 2025 10:25:29 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id ACEFD1D16; Tue, 11 Mar 2025 10:25:25 -0400 (EDT) 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 58B4D1CB6 for ; Tue, 11 Mar 2025 10:24:59 -0400 (EDT) Received: from mx-prod-mc-02.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-138-LB6cWUGDMzSB0Vf9jOmhhA-1; Tue, 11 Mar 2025 10:24:57 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BF01219560B8 for ; Tue, 11 Mar 2025 14:24:56 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.44]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 95CED1955BCB; Tue, 11 Mar 2025 14:24:55 +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=1741703099; 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=ND+JvUgFlD/tc2V+XWNKO6GulCoPsmwqqd8aPS7gQEo=; b=hHJKzJhqtmehSC/mRwAfhgVRAUvjvclIAEdG0P7YtP3ovIeiiFEq3MyhswXQ2vidc9ORWo 7Kz7pV6nkYX3GrG7aQ9S1rN4llF0Z9sFt13Fqxq9eEhskn4lVpbV6KGUHLJ3Vdcr51zSC2 ssPQTA5Fp3pZKA6Py1ya31IBdp25sg4= X-MC-Unique: LB6cWUGDMzSB0Vf9jOmhhA-1 X-Mimecast-MFC-AGG-ID: LB6cWUGDMzSB0Vf9jOmhhA_1741703096 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 v2 14/23] src: add constants for domain stats 'vcpu.' parameters Date: Tue, 11 Mar 2025 14:24:20 +0000 Message-ID: <20250311142429.1326816-15-berrange@redhat.com> In-Reply-To: <20250311142429.1326816-1-berrange@redhat.com> References: <20250311142429.1326816-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: FAcSK-dxsqdX_9vey1pM-B4eYqcuYa2hBZXMFpkavr4_1741703096 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TZALTXTR4JB3HEEFCELMG7CPWS5GPHZO X-Message-ID-Hash: TZALTXTR4JB3HEEFCELMG7CPWS5GPHZO 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: 1741703567436019100 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. Reviewed-by: Peter Krempa Signed-off-by: Daniel P. Berrang=C3=A9 --- include/libvirt/libvirt-domain.h | 123 +++++++++++++++++++++++++++++++ src/libvirt-domain.c | 44 +++-------- src/qemu/qemu_driver.c | 39 ++++++---- 3 files changed, 161 insertions(+), 45 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 719eda116a..8a18de208d 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -3079,6 +3079,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 aggregate 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 a8c4b8cfc1..343e7db01d 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -12256,43 +12256,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 27b8997226..e5a93fa6be 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17050,14 +17050,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: @@ -17072,14 +17073,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); } } } @@ -17100,8 +17101,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)); @@ -17132,17 +17135,26 @@ 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_DOMA= IN_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_D= OMAIN_STATS_VCPU_SUFFIX_TIME, + cpuinfo[i].number); + virTypedParamListAddULLong(params, cpuwait[i], + VIR_DOMAIN_STATS_VCPU_PREFIX "%u" VIR_D= OMAIN_STATS_VCPU_SUFFIX_WAIT, + cpuinfo[i].number); + virTypedParamListAddULLong(params, cpudelay[i], + VIR_DOMAIN_STATS_VCPU_PREFIX "%u" VIR_D= OMAIN_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))) @@ -17152,7 +17164,8 @@ 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_HALTED, + cpuinfo[i].number); } =20 if (!queried_stats) --=20 2.48.1