From nobody Sat Feb 7 08:27:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1542029703723805.3565527468602; Mon, 12 Nov 2018 05:35:03 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id A43A988E51; Mon, 12 Nov 2018 13:35:01 +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 56E1F5EDE0; Mon, 12 Nov 2018 13:35:01 +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 E66CC14B20; Mon, 12 Nov 2018 13:35:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wACDY0JU020004 for ; Mon, 12 Nov 2018 08:34:00 -0500 Received: by smtp.corp.redhat.com (Postfix) id 452205D757; Mon, 12 Nov 2018 13:34:00 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3073F5D738; Mon, 12 Nov 2018 13:33:57 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ADF5C31256A1; Mon, 12 Nov 2018 13:33:55 +0000 (UTC) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Nov 2018 05:33:55 -0800 Received: from david-unc.bj.intel.com ([10.238.145.63]) by orsmga004.jf.intel.com with ESMTP; 12 Nov 2018 05:33:53 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,495,1534834800"; d="scan'208";a="249041320" From: Wang Huaqiang To: jferlan@redhat.com, libvir-list@redhat.com Date: Mon, 12 Nov 2018 21:31:47 +0800 Message-Id: <1542029508-25671-17-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1542029508-25671-1-git-send-email-huaqiang.wang@intel.com> References: <1542029508-25671-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 12 Nov 2018 13:33:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Mon, 12 Nov 2018 13:33:56 +0000 (UTC) for IP:'192.55.52.93' DOMAIN:'mga11.intel.com' HELO:'mga11.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -5.001 (RCVD_IN_DNSWL_HI, SPF_PASS) 192.55.52.93 mga11.intel.com 192.55.52.93 mga11.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, huaqiang.wang@intel.com, rui.zang@intel.com, jian-feng.ding@intel.com Subject: [libvirt] [PATCHv8 16/17] qemu: Report cache occupancy (CMT) with domstats 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 12 Nov 2018 13:35:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Adding the interface in qemu to report CMT statistic information through command 'virsh domstats --cpu-total'. Below is a typical output: # virsh domstats 1 --cpu-total Domain: 'ubuntu16.04-base' ... cpu.cache.monitor.count=3D2 cpu.cache.monitor.0.name=3Dvcpus_1 cpu.cache.monitor.0.vcpus=3D1 cpu.cache.monitor.0.bank.count=3D2 cpu.cache.monitor.0.bank.0.id=3D0 cpu.cache.monitor.0.bank.0.bytes=3D4505600 cpu.cache.monitor.0.bank.1.id=3D1 cpu.cache.monitor.0.bank.1.bytes=3D5586944 cpu.cache.monitor.1.name=3Dvcpus_4-6 cpu.cache.monitor.1.vcpus=3D4,5,6 cpu.cache.monitor.1.bank.count=3D2 cpu.cache.monitor.1.bank.0.id=3D0 cpu.cache.monitor.1.bank.0.bytes=3D17571840 cpu.cache.monitor.1.bank.1.id=3D1 cpu.cache.monitor.1.bank.1.bytes=3D29106176 Signed-off-by: Wang Huaqiang --- src/libvirt-domain.c | 9 +++ src/qemu/qemu_driver.c | 198 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 207 insertions(+) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 7690339..4895f9f 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -11345,6 +11345,15 @@ virConnectGetDomainCapabilities(virConnectPtr conn, * "cpu.user" - user cpu time spent in nanoseconds as unsigned long lo= ng. * "cpu.system" - system cpu time spent in nanoseconds as unsigned long * long. + * "cpu.cache.monitor.count" - tocal cache monitoring groups + * "cpu.cache.monitor.M.name" - name of cache monitoring group 'M' + * "cpu.cache.monitor.M.vcpus" - vcpus for cache monitoring group 'M' + * "cpu.cache.monitor.M.bank.count" - total bank number of cache monit= oring + * group 'M' + * "cpu.cache.monitor.M.bank.N.id" - OS assigned cache bank id for cac= he + * 'N' in cache monitoring group 'M' + * "cpu.cache.monitor.M.bank.N.bytes" - monitor's cache occupancy of c= ache + * bank 'N' in cache monitoring group 'M' * * VIR_DOMAIN_STATS_BALLOON: * Return memory balloon device information. diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 89d46ee..d41ae66 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -19698,6 +19698,199 @@ typedef enum { #define HAVE_JOB(flags) ((flags) & QEMU_DOMAIN_STATS_HAVE_JOB) =20 =20 +typedef struct _virQEMUCpuResMonitorData virQEMUCpuResMonitorData; +typedef virQEMUCpuResMonitorData *virQEMUCpuResMonitorDataPtr; +struct _virQEMUCpuResMonitorData{ + const char *name; + char *vcpus; + virResctrlMonitorType tag; + virResctrlMonitorStatsPtr stats; + size_t nstats; +}; + + +static int +qemuDomainGetCpuResMonitorData(virDomainObjPtr dom, + virQEMUCpuResMonitorDataPtr mondata) +{ + virDomainResctrlDefPtr resctrl =3D NULL; + size_t i =3D 0; + size_t j =3D 0; + size_t l =3D 0; + + for (i =3D 0; i < dom->def->nresctrls; i++) { + resctrl =3D dom->def->resctrls[i]; + + for (j =3D 0; j < resctrl->nmonitors; j++) { + virDomainResctrlMonDefPtr domresmon =3D NULL; + virResctrlMonitorPtr monitor =3D resctrl->monitors[j]->instanc= e; + + domresmon =3D resctrl->monitors[j]; + mondata[l].tag =3D domresmon->tag; + + /* If virBitmapFormat successfully returns an vcpu string, then + * mondata[l].vcpus is assigned with an memory space holding i= t, + * let this newly allocated memory buffer to be freed along wi= th + * the free of 'mondata' */ + if (!(mondata[l].vcpus =3D virBitmapFormat(domresmon->vcpus))) + return -1; + + if (!(mondata[l].name =3D virResctrlMonitorGetID(monitor))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not get monitor ID")); + return -1; + } + + if (domresmon->tag =3D=3D VIR_RESCTRL_MONITOR_TYPE_CACHE) { + if (virResctrlMonitorGetCacheOccupancy(monitor, + &mondata[l].stats, + &mondata[l].nstats)= < 0) + return -1; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Invalid CPU resource type")); + return -1; + } + + l++; + } + } + + return 0; +} + + +static int +qemuDomainGetStatsCpuResMonitorPerTag(virQEMUCpuResMonitorDataPtr mondata, + size_t nmondata, + virResctrlMonitorType tag, + virDomainStatsRecordPtr record, + int *maxparams) +{ + char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; + unsigned int nmonitors =3D 0; + const char *resname =3D NULL; + const char *resnodename =3D NULL; + size_t i =3D 0; + + for (i =3D 0; i < nmondata; i++) { + if (mondata[i].tag =3D=3D tag) + nmonitors++; + } + + if (!nmonitors) + return 0; + + if (tag =3D=3D VIR_RESCTRL_MONITOR_TYPE_CACHE) { + resname =3D "cache"; + resnodename =3D "bank"; + } else if (tag =3D=3D VIR_RESCTRL_MONITOR_TYPE_MEMBW) { + resname =3D "memBW"; + resnodename =3D "node"; + } else { + return 0; + } + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.%s.monitor.count", resname); + if (virTypedParamsAddUInt(&record->params, &record->nparams, + maxparams, param_name, nmonitors) < 0) + return -1; + + for (i =3D 0; i < nmonitors; i++) { + size_t l =3D 0; + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.%s.monitor.%zd.name", resname, i); + if (virTypedParamsAddString(&record->params, + &record->nparams, + maxparams, + param_name, + mondata[i].name) < 0) + return -1; + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.%s.monitor.%zd.vcpus", resname, i); + if (virTypedParamsAddString(&record->params, &record->nparams, + maxparams, param_name, + mondata[i].vcpus) < 0) + return -1; + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.%s.monitor.%zd.%s.count", resname, i, resnodename); + if (virTypedParamsAddUInt(&record->params, &record->nparams, + maxparams, param_name, + mondata[i].nstats) < 0) + return -1; + + for (l =3D 0; l < mondata[i].nstats; l++) { + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.%s.monitor.%zd.%s.%zd.id", + resname, i, resnodename, l); + if (virTypedParamsAddUInt(&record->params, &record->nparams, + maxparams, param_name, + mondata[i].stats[l].id) < 0) + return -1; + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.%s.monitor.%zd.%s.%zd.bytes", + resname, i, resnodename, l); + if (virTypedParamsAddUInt(&record->params, &record->nparams, + maxparams, param_name, + mondata[i].stats[l].val) < 0) + return -1; + } + } + + return 0; +} + + +static int +qemuDomainGetStatsCpuResMonitor(virDomainObjPtr dom, + virDomainStatsRecordPtr record, + int *maxparams) +{ + virDomainResctrlDefPtr resctrl =3D NULL; + virQEMUCpuResMonitorDataPtr mondata =3D NULL; + unsigned int nmonitors =3D 0; + size_t i =3D 0; + int ret =3D -1; + + if (!virDomainObjIsActive(dom)) + return 0; + + for (i =3D 0; i < dom->def->nresctrls; i++) { + resctrl =3D dom->def->resctrls[i]; + nmonitors +=3D resctrl->nmonitors; + } + + if (!nmonitors) + return 0; + + if (VIR_ALLOC_N(mondata, nmonitors) < 0) + return -1; + + if (qemuDomainGetCpuResMonitorData(dom, mondata) < 0) + goto cleanup; + + for (i =3D VIR_RESCTRL_MONITOR_TYPE_UNSUPPORT + 1; + i < VIR_RESCTRL_MONITOR_TYPE_LAST; i++) { + if (qemuDomainGetStatsCpuResMonitorPerTag(mondata, nmonitors, i, + record, maxparams) < 0) + goto cleanup; + } + + ret =3D 0; + cleanup: + for (i =3D 0; i < nmonitors; i++) + VIR_FREE(mondata[i].vcpus); + VIR_FREE(mondata); + + return ret; +} + + static int qemuDomainGetStatsCpuCgroup(virDomainObjPtr dom, virDomainStatsRecordPtr record, @@ -19747,6 +19940,11 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTR= IBUTE_UNUSED, { if (qemuDomainGetStatsCpuCgroup(dom, record, maxparams) < 0) return -1; + + if (qemuDomainGetStatsCpuResMonitor(dom, record, maxparams) < 0) + return -1; + + return 0; } =20 =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list