From nobody Mon Feb 9 03:13:11 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 1531121544561101.84024202902424; Mon, 9 Jul 2018 00:32:24 -0700 (PDT) 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 20A1E30820E6; Mon, 9 Jul 2018 07:32:23 +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 E48445D6B4; Mon, 9 Jul 2018 07:32:22 +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 98B493F64F; Mon, 9 Jul 2018 07:32:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w697WBGU015323 for ; Mon, 9 Jul 2018 03:32:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0AF7D413D; Mon, 9 Jul 2018 07:32:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01B915DD73 for ; Mon, 9 Jul 2018 07:32:10 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 9F26730832C2 for ; Mon, 9 Jul 2018 07:32:09 +0000 (UTC) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jul 2018 00:32:09 -0700 Received: from david-unc.bj.intel.com ([10.238.145.77]) by fmsmga004.fm.intel.com with ESMTP; 09 Jul 2018 00:32:08 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,329,1526367600"; d="scan'208";a="69734039" From: Wang Huaqiang To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 15:00:57 +0800 Message-Id: <1531119658-18549-10-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1531119658-18549-1-git-send-email-huaqiang.wang@intel.com> References: <1531119658-18549-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 09 Jul 2018 07:32:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 09 Jul 2018 07:32:09 +0000 (UTC) for IP:'192.55.52.88' DOMAIN:'mga01.intel.com' HELO:'mga01.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -5.001 (RCVD_IN_DNSWL_HI, SPF_PASS) 192.55.52.88 mga01.intel.com 192.55.52.88 mga01.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.44 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: shaohe.feng@intel.com, Wang Huaqiang , bing.niu@intel.com, jian-feng.ding@intel.com, rui.zang@intel.com Subject: [libvirt] [PATCHv2 09/10] tools: show cpu cache occupancy information in 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.47]); Mon, 09 Jul 2018 07:32:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" add cache occupancy information in command virsh domstats for domains has resource monitoring groups. --- include/libvirt/libvirt-domain.h | 1 + src/qemu/qemu_driver.c | 105 +++++++++++++++++++++++++++++++++++= ++++ tools/virsh-domain-monitor.c | 7 +++ 3 files changed, 113 insertions(+) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index c703346..c7ee425 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2041,6 +2041,7 @@ typedef enum { VIR_DOMAIN_STATS_INTERFACE =3D (1 << 4), /* return domain interfaces i= nfo */ VIR_DOMAIN_STATS_BLOCK =3D (1 << 5), /* return domain block info */ VIR_DOMAIN_STATS_PERF =3D (1 << 6), /* return domain perf event info */ + VIR_DOMAIN_STATS_CPU_RES =3D (1<<7), /* return CPU resource info */ } virDomainStatsTypes; =20 typedef enum { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 647d864..9b6e3fe 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20330,6 +20330,110 @@ qemuDomainGetStatsPerf(virQEMUDriverPtr driver AT= TRIBUTE_UNUSED, return ret; } =20 + +static int +qemuDomainGetStatsCPUResmon(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, + virDomainObjPtr vm, + virDomainStatsRecordPtr record, + int *maxparams, + unsigned int privflags ATTRIBUTE_UNUSED) +{ + char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; + size_t i =3D 0; + size_t l =3D 0; + unsigned int llc_occu =3D 0; + int ret =3D -1; + char *vcpustr =3D NULL; + + for (i =3D 0; i < vm->def->nresmons; i++) { + virDomainCpuResmonDefPtr resmon =3D vm->def->resmons[i]; + + llc_occu =3D 0; + if (virResctrlMonIsRunning(resmon->mon)) { + if (virResctrlMonGetCacheOccupancy(resmon->mon, &llc_occu) < 0) + goto cleanup; + } + + const char *mon_id =3D virResctrlMonGetID(resmon->mon); + if (!mon_id) + goto cleanup; + if (!(vcpustr =3D virBitmapFormat(resmon->vcpus))) + goto cleanup; + + /* for vcpu string, both '1-3' and '1,3' are valid format and + * representing different vcpu set. But it is not easy to + * differentiate them at first galance, to avoid this case + * substituting all '-' with ',', e.g. substitute '1-3' with + * '1,2,3' */ + for (l =3D 0; l < strlen(vcpustr); l++) { + if (vcpustr[l] =3D=3D '-') { + char strbuf[256]; + unsigned int cpul =3D 0; + unsigned int cpur =3D 0; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + unsigned int icpu =3D 0; + char *tmp =3D NULL; + + /* virStrToLong_ui is very tricking in processing '-'. to + * avoid to trigger error, replace '-' with '_' */ + vcpustr[l] =3D '_'; + + if (virStrToLong_ui(vcpustr, &tmp, 10, &cpul) < 0) + goto cleanup; + if (virStrToLong_ui(vcpustr + l + 1, &tmp, 10, &cpur) < 0) + goto cleanup; + if (cpur < cpul) + goto cleanup; + + for (icpu =3D cpul; icpu <=3D cpur; icpu++) { + snprintf(strbuf, 256, "%d", icpu); + virBufferStrcat(&buf, strbuf, NULL); + if (icpu !=3D cpur) + virBufferStrcat(&buf, ",", NULL); + } + + VIR_FREE(vcpustr); + vcpustr =3D virBufferContentAndReset(&buf); + + break; + } + } + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cacheoccupancy.%s.value", + mon_id); + + if (virTypedParamsAddInt(&record->params, + &record->nparams, + maxparams, + param_name, + llc_occu) < 0) { + goto cleanup; + } + + snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, + "cpu.cacheoccupancy.%s.vcpus", + mon_id); + + if (virTypedParamsAddString(&record->params, + &record->nparams, + maxparams, + param_name, + vcpustr) < 0) { + goto cleanup; + } + + VIR_FREE(vcpustr); + vcpustr =3D NULL; + } + + ret =3D 0; + cleanup: + VIR_FREE(vcpustr); + return ret; +} + + typedef int (*qemuDomainGetStatsFunc)(virQEMUDriverPtr driver, virDomainObjPtr dom, @@ -20351,6 +20455,7 @@ static struct qemuDomainGetStatsWorker qemuDomainGe= tStatsWorkers[] =3D { { qemuDomainGetStatsInterface, VIR_DOMAIN_STATS_INTERFACE, false }, { qemuDomainGetStatsBlock, VIR_DOMAIN_STATS_BLOCK, true }, { qemuDomainGetStatsPerf, VIR_DOMAIN_STATS_PERF, false }, + { qemuDomainGetStatsCPUResmon, VIR_DOMAIN_STATS_CPU_RES, false }, { NULL, 0, false } }; =20 diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 87660ee..5f65f3d 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -2099,6 +2099,10 @@ static const vshCmdOptDef opts_domstats[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("report only stats that are accessible instantly"), }, + {.name =3D "cpu-resource", + .type =3D VSH_OT_BOOL, + .help =3D N_("report cpu resource information"), + }, VIRSH_COMMON_OPT_DOMAIN_OT_ARGV(N_("list of domains to get stats for")= , 0), {.name =3D NULL} }; @@ -2164,6 +2168,9 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "perf")) stats |=3D VIR_DOMAIN_STATS_PERF; =20 + if (vshCommandOptBool(cmd, "cpu-resource")) + stats |=3D VIR_DOMAIN_STATS_CPU_RES; + if (vshCommandOptBool(cmd, "list-active")) flags |=3D VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE; =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list