From nobody Tue May 7 10:59:32 2024 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 1542722311304541.2273078607059; Tue, 20 Nov 2018 05:58:31 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C43DC88E44; Tue, 20 Nov 2018 13:58:28 +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 929C2105B1EF; Tue, 20 Nov 2018 13:58:28 +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 4EC03181B9E5; Tue, 20 Nov 2018 13:58:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wAKDwRl4020009 for ; Tue, 20 Nov 2018 08:58:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id A3259662FC; Tue, 20 Nov 2018 13:58:27 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DCB7666D40; Tue, 20 Nov 2018 13:58:22 +0000 (UTC) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 5C29F30820F2; Tue, 20 Nov 2018 13:58:21 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 05:58:20 -0800 Received: from david-unc.bj.intel.com ([10.238.145.63]) by fmsmga004.fm.intel.com with ESMTP; 20 Nov 2018 05:58:19 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,257,1539673200"; d="scan'208";a="107823960" From: Wang Huaqiang To: jferlan@redhat.com, libvir-list@redhat.com Date: Tue, 20 Nov 2018 21:56:31 +0800 Message-Id: <1542722192-28146-2-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1542722192-28146-1-git-send-email-huaqiang.wang@intel.com> References: <1542722192-28146-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.47]); Tue, 20 Nov 2018 13:58:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 20 Nov 2018 13:58:21 +0000 (UTC) for IP:'134.134.136.24' DOMAIN:'mga09.intel.com' HELO:'mga09.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -5.001 (RCVD_IN_DNSWL_HI, SPF_PASS) 134.134.136.24 mga09.intel.com 134.134.136.24 mga09.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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] [PATCHv9 1/2] 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 20 Nov 2018 13:58:29 +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 | 12 ++++ src/qemu/qemu_driver.c | 160 +++++++++++++++++++++++++++++++++++++++++++++= +++- tools/virsh.pod | 14 +++++ 3 files changed, 185 insertions(+), 1 deletion(-) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 5b76458..73d602e 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -11415,6 +11415,18 @@ 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" - the number of cache monitors for this d= omain + * "cpu.cache.monitor..name" - the name of cache monitor + * "cpu.cache.monitor..vcpus" - vcpu list of cache monitor + * "cpu.cache.monitor..bank.count" - the number of cache banks in + * cache monitor + * "cpu.cache.monitor..bank..id" - host allocated cache id= for + * bank in cache + * monitor + * "cpu.cache.monitor..bank..bytes" - the number of bytes = of + * last level cache tha= t the + * domain is using on c= ache + * bank * * VIR_DOMAIN_STATS_BALLOON: * Return memory balloon device information. diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7fb9102..d9e216c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -19929,6 +19929,158 @@ typedef enum { #define HAVE_JOB(flags) ((flags) & QEMU_DOMAIN_STATS_HAVE_JOB) =20 =20 +typedef struct _virQEMUResctrlMonData virQEMUResctrlMonData; +typedef virQEMUResctrlMonData *virQEMUResctrlMonDataPtr; +struct _virQEMUResctrlMonData { + const char *name; + char *vcpus; + virResctrlMonitorStatsPtr stats; + size_t nstats; +}; + + +static int +qemuDomainGetResctrlMonData(virDomainObjPtr dom, + virQEMUResctrlMonDataPtr resdata) +{ + virDomainResctrlDefPtr resctrl =3D NULL; + size_t i =3D 0; + size_t j =3D 0; + size_t k =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 NULL; + + domresmon =3D resctrl->monitors[j]; + monitor =3D domresmon->instance; + + if (domresmon->tag !=3D VIR_RESCTRL_MONITOR_TYPE_CACHE) + continue; + + /* If virBitmapFormat successfully returns an vcpu string, then + * resdata[k].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 'resdata' */ + if (!(resdata[k].vcpus =3D virBitmapFormat(domresmon->vcpus))) + return -1; + + if (!(resdata[k].name =3D virResctrlMonitorGetID(monitor))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not get monitor ID")); + return -1; + } + + if (virResctrlMonitorGetCacheOccupancy(monitor, + &resdata[k].stats, + &resdata[k].nstats) < 0) + return -1; + + k++; + } + } + + return 0; +} + + +static int +qemuDomainGetStatsCpuCache(virDomainObjPtr dom, + virDomainStatsRecordPtr record, + int *maxparams) +{ + char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; + virQEMUResctrlMonDataPtr resdata =3D NULL; + virDomainResctrlDefPtr resctrl =3D NULL; + virDomainResctrlMonDefPtr domresmon =3D NULL; + unsigned int nresdata =3D 0; + size_t i =3D 0; + size_t j =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]; + for (j =3D 0; j < resctrl->nmonitors; j++) { + domresmon =3D resctrl->monitors[j]; + if (domresmon->tag =3D=3D VIR_RESCTRL_MONITOR_TYPE_CACHE) + nresdata++; + } + } + + if (nresdata =3D=3D 0) + return 0; + + if (VIR_ALLOC_N(resdata, nresdata) < 0) + return -1; + + if (qemuDomainGetResctrlMonData(dom, resdata) < 0) + goto cleanup; + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cache.monitor.count"); + if (virTypedParamsAddUInt(&record->params, &record->nparams, + maxparams, param_name, nresdata) < 0) + goto cleanup; + + for (i =3D 0; i < nresdata; i++) { + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cache.monitor.%zu.name", i); + if (virTypedParamsAddString(&record->params, + &record->nparams, + maxparams, + param_name, + resdata[i].name) < 0) + goto cleanup; + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cache.monitor.%zu.vcpus", i); + if (virTypedParamsAddString(&record->params, &record->nparams, + maxparams, param_name, + resdata[i].vcpus) < 0) + goto cleanup; + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cache.monitor.%zu.bank.count", i); + if (virTypedParamsAddUInt(&record->params, &record->nparams, + maxparams, param_name, + resdata[i].nstats) < 0) + goto cleanup; + + for (j =3D 0; j < resdata[i].nstats; j++) { + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cache.monitor.%zu.bank.%zu.id", i, j); + if (virTypedParamsAddUInt(&record->params, &record->nparams, + maxparams, param_name, + resdata[i].stats[j].id) < 0) + goto cleanup; + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cache.monitor.%zu.bank.%zu.bytes", i, j); + if (virTypedParamsAddUInt(&record->params, &record->nparams, + maxparams, param_name, + resdata[i].stats[j].val) < 0) + goto cleanup; + } + } + + ret =3D 0; + cleanup: + for (i =3D 0; i < nresdata; i++) { + VIR_FREE(resdata[i].vcpus); + VIR_FREE(resdata[i].stats); + } + VIR_FREE(resdata); + + return ret; +} + + static int qemuDomainGetStatsCpuCgroup(virDomainObjPtr dom, virDomainStatsRecordPtr record, @@ -19976,7 +20128,13 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver ATTR= IBUTE_UNUSED, int *maxparams, unsigned int privflags ATTRIBUTE_UNUSED) { - return qemuDomainGetStatsCpuCgroup(dom, record, maxparams); + if (qemuDomainGetStatsCpuCgroup(dom, record, maxparams) < 0) + return -1; + + if (qemuDomainGetStatsCpuCache(dom, record, maxparams) < 0) + return -1; + + return 0; } =20 =20 diff --git a/tools/virsh.pod b/tools/virsh.pod index 4876656..86a4996 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1012,6 +1012,20 @@ I<--cpu-total> returns: "cpu.time" - total cpu time spent for this domain in nanoseconds "cpu.user" - user cpu time spent in nanoseconds "cpu.system" - system cpu time spent in nanoseconds + "cpu.cache.monitor.count" - the number of cache monitors for this + domain + "cpu.cache.monitor..name" - the name of cache monitor + "cpu.cache.monitor..vcpus" - vcpu list of cache monitor + "cpu.cache.monitor..bank.count" - the number of cache banks + in cache monitor + "cpu.cache.monitor..bank..id" - host allocated cache id + for bank in + cache monitor + "cpu.cache.monitor..bank..bytes" - the number of bytes + of last level cache + that the domain is + using on cache bank + =20 I<--balloon> returns: =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 10:59:32 2024 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 1542722308950862.5405538708525; Tue, 20 Nov 2018 05:58:28 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4DEC9308625C; Tue, 20 Nov 2018 13:58:27 +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 0243660155; Tue, 20 Nov 2018 13:58:27 +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 5F1741800533; Tue, 20 Nov 2018 13:58:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wAKDwOGR019990 for ; Tue, 20 Nov 2018 08:58:24 -0500 Received: by smtp.corp.redhat.com (Postfix) id ACC4F2654D; Tue, 20 Nov 2018 13:58:24 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9405F19C7D; Tue, 20 Nov 2018 13:58:23 +0000 (UTC) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 8F2A064D87; Tue, 20 Nov 2018 13:58:22 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 05:58:22 -0800 Received: from david-unc.bj.intel.com ([10.238.145.63]) by fmsmga004.fm.intel.com with ESMTP; 20 Nov 2018 05:58:21 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,257,1539673200"; d="scan'208";a="107823970" From: Wang Huaqiang To: jferlan@redhat.com, libvir-list@redhat.com Date: Tue, 20 Nov 2018 21:56:32 +0800 Message-Id: <1542722192-28146-3-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1542722192-28146-1-git-send-email-huaqiang.wang@intel.com> References: <1542722192-28146-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.38]); Tue, 20 Nov 2018 13:58:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 20 Nov 2018 13:58:22 +0000 (UTC) for IP:'134.134.136.24' DOMAIN:'mga09.intel.com' HELO:'mga09.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -5.001 (RCVD_IN_DNSWL_HI, SPF_PASS) 134.134.136.24 mga09.intel.com 134.134.136.24 mga09.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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] [PATCHv9 2/2] docs: Updated news.xml for CMT 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 20 Nov 2018 13:58:27 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Wang Huaqiang --- docs/news.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/news.xml b/docs/news.xml index 4406aeb..deadb85 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -68,6 +68,18 @@ be viewed via the domain statistics. + + + qemu: Added support for CMT (Cache Monitoring Technology) + + + Introduced cache monitoring using the monitor + element in cachetune for vCPU threads. Added + interfaces to get and display the cache utilization statistics + through the command 'virsh domstats' via the + virConnectGetAllDomainStats API. + +
--=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list