From nobody Mon Feb 9 10:27:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1577961910; cv=none; d=zohomail.com; s=zohoarc; b=IecnzxTOetAQ/25dhPZP8Gemw2zZ6Zf8ABzFBchmCM8dsCdKJaO+KD2b+yktEld/2scvOhUml3TAxcH0vazo6GFLdNQ3Vxn4YS03Z6iNGStF5tV4/AshRP8vKVqB4eAiCJaA8Reu+ph6R1CzCS0aiwSws/8JOujAr88/SbhYh6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577961910; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=e1tqkhg07mSocZBI0yfhEJZVk1IilC2pvA5WmqmmQQA=; b=gWJTPvzcTEr9muHI9WRg2WU5KwA+tE/NFjTOZjfECZ/L3m2Qm0AjnV9sPjj8vxBWPI296acKHyHqLUYKUoAzPWbn6Pi+gN2ANgkDiXrxEuxoE+Ls3Y3LsJEI3UmKnFj4yXQS08vbkWNnK0qX7L6FSRaqIaOQh1x8AdIfYaS1KQo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1577961910388124.98865295463702; Thu, 2 Jan 2020 02:45:10 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-UxfBk9QZMiSACmiJlFDdvw-1; Thu, 02 Jan 2020 05:45:07 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BFC28800EB6; Thu, 2 Jan 2020 10:45:01 +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 A134B60C05; Thu, 2 Jan 2020 10:45:00 +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 6D44C18089CE; Thu, 2 Jan 2020 10:44:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 002Aiw2b028977 for ; Thu, 2 Jan 2020 05:44:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id DD1DD10D17BC; Thu, 2 Jan 2020 10:44:57 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D61B610D18F3 for ; Thu, 2 Jan 2020 10:44:55 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9A7998008A0 for ; Thu, 2 Jan 2020 10:44:55 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-378-MKWtsu9NPCisW18MI77cjw-2; Thu, 02 Jan 2020 05:44:53 -0500 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jan 2020 02:44:52 -0800 Received: from david-unc.bj.intel.com ([10.238.157.59]) by fmsmga008.fm.intel.com with ESMTP; 02 Jan 2020 02:44:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577961908; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=e1tqkhg07mSocZBI0yfhEJZVk1IilC2pvA5WmqmmQQA=; b=I9rIYAShrT9bsZLuEXpkNZRrlY+hTolUyD3ViHsVPsQWjWYeatxKsop00oNL6CBKkNkm3N ddseZtgdJU8jpHtQnkVLspAlhsJO0jn/4761XoILT9Sz8fJu/oWG+7HOtrzLQMqun7BA2+ SOwm2vUEGHoqjsmWmiFppa0bBvNxEOk= X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,386,1571727600"; d="scan'208";a="216477094" From: Wang Huaqiang To: libvir-list@redhat.com, berrange@redhat.com Date: Thu, 2 Jan 2020 18:45:05 +0800 Message-Id: <20200102104505.28461-3-huaqiang.wang@intel.com> In-Reply-To: <20200102104505.28461-1-huaqiang.wang@intel.com> References: <20200102104505.28461-1-huaqiang.wang@intel.com> MIME-Version: 1.0 X-MC-Unique: MKWtsu9NPCisW18MI77cjw-2 X-MC-Unique: UxfBk9QZMiSACmiJlFDdvw-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 002Aiw2b028977 X-loop: libvir-list@redhat.com Cc: huaqiang.wang@intel.com Subject: [libvirt] [PATCHv2 2/2] Introduce command 'virsh domstats --memory' for reporting memory BW 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Introduce an option '--memory' for showing memory related information. The memory bandwidth infomatio is listed as: Domain: 'libvirt-vm' memory.bandwidth.monitor.count=3D4 memory.bandwidth.monitor.0.name=3Dvcpus_0-4 memory.bandwidth.monitor.0.vcpus=3D0-4 memory.bandwidth.monitor.0.node.count=3D2 memory.bandwidth.monitor.0.node.0.id=3D0 memory.bandwidth.monitor.0.node.0.bytes.total=3D10208067584 memory.bandwidth.monitor.0.node.0.bytes.local=3D4807114752 memory.bandwidth.monitor.0.node.1.id=3D1 memory.bandwidth.monitor.0.node.1.bytes.total=3D8693735424 memory.bandwidth.monitor.0.node.1.bytes.local=3D5850161152 memory.bandwidth.monitor.1.name=3Dvcpus_7 memory.bandwidth.monitor.1.vcpus=3D7 memory.bandwidth.monitor.1.node.count=3D2 memory.bandwidth.monitor.1.node.0.id=3D0 memory.bandwidth.monitor.1.node.0.bytes.total=3D853811200 memory.bandwidth.monitor.1.node.0.bytes.local=3D290701312 memory.bandwidth.monitor.1.node.1.id=3D1 memory.bandwidth.monitor.1.node.1.bytes.total=3D406044672 memory.bandwidth.monitor.1.node.1.bytes.local=3D229425152 Signed-off-by: Wang Huaqiang Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/manpages/virsh.rst | 22 ++++++- include/libvirt/libvirt-domain.h | 1 + src/libvirt-domain.c | 21 +++++++ src/qemu/qemu_driver.c | 103 +++++++++++++++++++++++++++++++ tools/virsh-domain-monitor.c | 7 +++ 5 files changed, 152 insertions(+), 2 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index fea0527caf..d0f9e15c38 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -2186,7 +2186,7 @@ domstats =20 domstats [--raw] [--enforce] [--backing] [--nowait] [--state] [--cpu-total] [--balloon] [--vcpu] [--interface] - [--block] [--perf] [--iothread] + [--block] [--perf] [--iothread] [--memory] [[--list-active] [--list-inactive] [--list-persistent] [--list-transient] [--list-running]y [--list-paused] [--list-shutoff] [--list-other]] | [domain ...] @@ -2205,7 +2205,7 @@ behavior use the *--raw* flag. The individual statistics groups are selectable via specific flags. By default all supported statistics groups are returned. Supported statistics groups flags are: *--state*, *--cpu-total*, *--balloon*, -*--vcpu*, *--interface*, *--block*, *--perf*, *--iothread*. +*--vcpu*, *--interface*, *--block*, *--perf*, *--iothread*, *--memory*. =20 Note that - depending on the hypervisor type and version or the domain sta= te - not all of the following statistics may be returned. @@ -2372,6 +2372,24 @@ not available for statistical purposes. * ``iothread..poll-shrink`` - polling time shrink value. A value of (zero) indicates shrink is managed by hypervisor. =20 +*--memory* returns: + +* ``memory.bandwidth.monitor.count`` - the number of memory bandwidth + monitors for this domain +* ``memory.bandwidth.monitor..name`` - the name of monitor +* ``memory.bandwidth.monitor..vcpus`` - the vcpu list of monitor +* ``memory.bandwidth.monitor..node.count`` - the number of memory + controller in monitor +* ``memory.bandwidth.monitor..node..id`` - host allocated memo= ry + controller id for controller of monitor +* ``memory.bandwidth.monitor..node..bytes.local`` - the accumu= lative + bytes consumed by @vcpus that passing through the memory controller in t= he + same processor that the scheduled host CPU belongs to. +* ``memory.bandwidth.monitor..node..bytes.total`` - the total + bytes consumed by @vcpus that passing through all memory controllers, ei= ther + local or remote controller. + + Selecting a specific statistics groups doesn't guarantee that the daemon supports the selected group of stats. Flag *--enforce* forces the command to fail if the daemon doesn't support the diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index e60003978a..78532c0eb8 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -2160,6 +2160,7 @@ typedef enum { 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_IOTHREAD =3D (1 << 7), /* return iothread poll info */ + VIR_DOMAIN_STATS_MEMORY=3D (1 << 8), /* return domain memory info */ } virDomainStatsTypes; =20 typedef enum { diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 793eceb39f..eb66999f07 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -11640,6 +11640,27 @@ virConnectGetDomainCapabilities(virConnectPtr conn, * hypervisor to choose how to shrink the * polling time. * + * VIR_DOMAIN_STATS_MEMORY: + * Return memory bandwidth statistics and the usage information. The t= yped + * parameter keys are in this format: + * + * "memory.bandwidth.monitor.count" - the number of memory bandwidth + * monitors for this domain + * "memory.bandwidth.monitor..name" - the name of monitor + * "memory.bandwidth.monitor..vcpus" - the vcpu list of monitor <= num> + * "memory.bandwidth.monitor..node.count" - the number of memory + * controller in monitor + * "memory.bandwidth.monitor..node..id" - host allocated m= emory + * controller id for contr= oller + * of monitor + * "memory.bandwidth.monitor..node..bytes.local" - the + * accumulative bytes consumed by @vcpus that passing + * through the memory controller in the same process= or + * that the scheduled host CPU belongs to. + * "memory.bandwidth.monitor..node..bytes.total" - the tot= al + * bytes consumed by @vcpus that passing through all + * memory controllers, either local or remote contro= ller. + * * Note that entire stats groups or individual stat fields may be missing = from * the output in case they are not supported by the given hypervisor, are = not * applicable for the current state of the guest domain, or their retrieval diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ad6f3130ae..d91adcf52f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20649,6 +20649,9 @@ qemuDomainGetResctrlMonData(virQEMUDriverPtr driver, features =3D caps->host.cache.monitor->features; break; case VIR_RESCTRL_MONITOR_TYPE_MEMBW: + if (caps->host.memBW.monitor) + features =3D caps->host.memBW.monitor->features; + break; case VIR_RESCTRL_MONITOR_TYPE_UNSUPPORT: case VIR_RESCTRL_MONITOR_TYPE_LAST: virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s", @@ -20701,6 +20704,94 @@ qemuDomainGetResctrlMonData(virQEMUDriverPtr drive= r, } =20 =20 +static int +qemuDomainGetStatsMemoryBandwidth(virQEMUDriverPtr driver, + virDomainObjPtr dom, + virTypedParamListPtr params) +{ + virQEMUResctrlMonDataPtr *resdata =3D NULL; + char **features =3D NULL; + size_t nresdata =3D 0; + size_t i =3D 0; + size_t j =3D 0; + size_t k =3D 0; + int ret =3D -1; + + if (!virDomainObjIsActive(dom)) + return 0; + + if (qemuDomainGetResctrlMonData(driver, dom, &resdata, &nresdata, + VIR_RESCTRL_MONITOR_TYPE_MEMBW) < 0) + goto cleanup; + + if (nresdata =3D=3D 0) + return 0; + + if (virTypedParamListAddUInt(params, nresdata, + "memory.bandwidth.monitor.count") < 0) + goto cleanup; + + for (i =3D 0; i < nresdata; i++) { + if (virTypedParamListAddString(params, resdata[i]->name, + "memory.bandwidth.monitor.%zu.name", + i) < 0) + goto cleanup; + + if (virTypedParamListAddString(params, resdata[i]->vcpus, + "memory.bandwidth.monitor.%zu.vcpus= ", + i) < 0) + goto cleanup; + + if (virTypedParamListAddUInt(params, resdata[i]->nstats, + "memory.bandwidth.monitor.%zu.node.co= unt", + i) < 0) + goto cleanup; + + + for (j =3D 0; j < resdata[i]->nstats; j++) { + if (virTypedParamListAddUInt(params, resdata[i]->stats[j]->id, + "memory.bandwidth.monitor.%zu." + "node.%zu.id", + i, j) < 0) + goto cleanup; + + + features =3D resdata[i]->stats[j]->features; + for (k =3D 0; features[k]; k++) { + if (STREQ(features[k], "mbm_local_bytes")) { + /* The accumulative data passing through local memory + * controller is recorded with 64 bit counter. */ + if (virTypedParamListAddULLong(params, + resdata[i]->stats[j]->v= als[k], + "memory.bandwidth.monit= or." + "%zu.node.%zu.bytes.loc= al", + i, j) < 0) + goto cleanup; + } + + if (STREQ(features[k], "mbm_total_bytes")) { + /* The accumulative data passing through local and rem= ote + * memory controller is recorded with 64 bit counter. = */ + if (virTypedParamListAddULLong(params, + resdata[i]->stats[j]->v= als[k], + "memory.bandwidth.monit= or." + "%zu.node.%zu.bytes.tot= al", + i, j) < 0) + goto cleanup; + } + } + } + } + + ret =3D 0; + cleanup: + for (i =3D 0; i < nresdata; i++) + qemuDomainFreeResctrlMonData(resdata[i]); + VIR_FREE(resdata); + return ret; +} + + static int qemuDomainGetStatsCpuCache(virQEMUDriverPtr driver, virDomainObjPtr dom, @@ -20809,6 +20900,17 @@ qemuDomainGetStatsCpu(virQEMUDriverPtr driver, } =20 =20 +static int +qemuDomainGetStatsMemory(virQEMUDriverPtr driver, + virDomainObjPtr dom, + virTypedParamListPtr params, + unsigned int privflags G_GNUC_UNUSED) + +{ + return qemuDomainGetStatsMemoryBandwidth(driver, dom, params); +} + + static int qemuDomainGetStatsBalloon(virQEMUDriverPtr driver, virDomainObjPtr dom, @@ -21478,6 +21580,7 @@ static struct qemuDomainGetStatsWorker qemuDomainGe= tStatsWorkers[] =3D { { qemuDomainGetStatsBlock, VIR_DOMAIN_STATS_BLOCK, true }, { qemuDomainGetStatsPerf, VIR_DOMAIN_STATS_PERF, false }, { qemuDomainGetStatsIOThread, VIR_DOMAIN_STATS_IOTHREAD, true }, + { qemuDomainGetStatsMemory, VIR_DOMAIN_STATS_MEMORY, false }, { NULL, 0, false } }; =20 diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index c2f157ad6b..7b9b9c57b0 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -2111,6 +2111,10 @@ static const vshCmdOptDef opts_domstats[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("report domain IOThread information"), }, + {.name =3D "memory", + .type =3D VSH_OT_BOOL, + .help =3D N_("report domain memory usage"), + }, {.name =3D "list-active", .type =3D VSH_OT_BOOL, .help =3D N_("list only active domains"), @@ -2227,6 +2231,9 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "iothread")) stats |=3D VIR_DOMAIN_STATS_IOTHREAD; =20 + if (vshCommandOptBool(cmd, "memory")) + stats |=3D VIR_DOMAIN_STATS_MEMORY; + if (vshCommandOptBool(cmd, "list-active")) flags |=3D VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE; =20 --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list