From nobody Thu Jul 3 22:55:45 2025 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 1529056381152645.4246351486871; Fri, 15 Jun 2018 02:53:01 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 17F0B30D296D; Fri, 15 Jun 2018 09:53:00 +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 C5D6595A67; Fri, 15 Jun 2018 09:52:59 +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 6B293180053D; Fri, 15 Jun 2018 09:52:59 +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 w5F9qnZC007068 for ; Fri, 15 Jun 2018 05:52:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 641BF261A6; Fri, 15 Jun 2018 09:52:49 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5E7EF2618E for ; Fri, 15 Jun 2018 09:52:49 +0000 (UTC) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 017D087631 for ; Fri, 15 Jun 2018 09:52:48 +0000 (UTC) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jun 2018 02:52:47 -0700 Received: from bing-i9.bj.intel.com ([172.16.182.85]) by orsmga001.jf.intel.com with ESMTP; 15 Jun 2018 02:52:46 -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,226,1526367600"; d="scan'208";a="64805895" From: bing.niu@intel.com To: libvir-list@redhat.com Date: Fri, 15 Jun 2018 17:29:29 +0800 Message-Id: <1529054969-68474-6-git-send-email-bing.niu@intel.com> In-Reply-To: <1529054969-68474-1-git-send-email-bing.niu@intel.com> References: <1529054969-68474-1-git-send-email-bing.niu@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.26]); Fri, 15 Jun 2018 09:52:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 15 Jun 2018 09:52:48 +0000 (UTC) for IP:'134.134.136.31' DOMAIN:'mga06.intel.com' HELO:'mga06.intel.com' FROM:'bing.niu@intel.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 134.134.136.31 mga06.intel.com 134.134.136.31 mga06.intel.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 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, Bing Niu , jian-feng.ding@intel.com, rui.zang@yandex.com Subject: [libvirt] [RFCv2 PATCH 5/5] conf: add memory bandwidth allocation capability of host 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 15 Jun 2018 09:53:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Bing Niu Add new XML section to report host's memory bandwidth allocation capability. The format as below example: ..... granularity ---- granularity of memory bandwidth, unit percentage. min ---- minimum memory bandwidth allowed, unit percentage. maxAllocs ---- maximum memory bandwidth allocation group supported. Signed-off-by: Bing Niu --- src/conf/capabilities.c | 108 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/conf/capabilities.h | 11 +++++ src/util/virresctrl.c | 20 +++++++++ src/util/virresctrl.h | 15 +++++++ 4 files changed, 154 insertions(+) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 7a810ef..3bba153 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -198,6 +198,16 @@ virCapabilitiesFreeNUMAInfo(virCapsPtr caps) } =20 static void +virCapsHostMemoryNodeFree(virCapsHostMemoryNodePtr ptr) +{ + if (!ptr) + return; + + virBitmapFree(ptr->cpus); + VIR_FREE(ptr); +} + +static void virCapabilitiesClearSecModel(virCapsHostSecModelPtr secmodel) { size_t i; @@ -239,6 +249,11 @@ virCapsDispose(void *object) virCapsHostCacheBankFree(caps->host.caches[i]); VIR_FREE(caps->host.caches); =20 + for (i =3D 0; i < caps->host.nnodes; i++) + virCapsHostMemoryNodeFree(caps->host.nodes[i]); + VIR_FREE(caps->host.nodes); + + VIR_FREE(caps->host.netprefix); VIR_FREE(caps->host.pagesSize); virCPUDefFree(caps->host.cpu); @@ -957,6 +972,58 @@ virCapabilitiesFormatCaches(virBufferPtr buf, return 0; } =20 +static int +virCapabilitiesFormatMemory(virBufferPtr buf, + size_t nnodes, + virCapsHostMemoryNodePtr *nodes) +{ + size_t i =3D 0; + virBuffer controlBuf =3D VIR_BUFFER_INITIALIZER; + + if (!nnodes) + return 0; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + for (i =3D 0; i < nnodes; i++) { + virCapsHostMemoryNodePtr node =3D nodes[i]; + virResctrlInfoPerNodePtr control =3D &node->control; + char *cpus_str =3D virBitmapFormat(node->cpus); + + if (!cpus_str) + return -1; + + virBufferAsprintf(buf, + "id, cpus_str); + VIR_FREE(cpus_str); + + virBufferSetChildIndent(&controlBuf, buf); + virBufferAsprintf(&controlBuf, + "\n", + control->granularity, control->min, + control->max_allocation); + + if (virBufferCheckError(&controlBuf) < 0) + return -1; + + if (virBufferUse(&controlBuf)) { + virBufferAddLit(buf, ">\n"); + virBufferAddBuffer(buf, &controlBuf); + virBufferAddLit(buf, "\n"); + } else { + virBufferAddLit(buf, "/>\n"); + } + } + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + return 0; +} + /** * virCapabilitiesFormatXML: * @caps: capabilities to format @@ -1060,6 +1127,10 @@ virCapabilitiesFormatXML(virCapsPtr caps) caps->host.caches) < 0) goto error; =20 + if (virCapabilitiesFormatMemory(&buf, caps->host.nnodes, + caps->host.nodes) < 0) + goto error; + for (i =3D 0; i < caps->host.nsecModels; i++) { virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); @@ -1602,6 +1673,40 @@ virCapabilitiesInitResctrl(virCapsPtr caps) } =20 =20 +static int +virCapabilitiesInitResctrlMemory(virCapsPtr caps) +{ + virCapsHostMemoryNodePtr node =3D NULL; + size_t i =3D 0; + int ret =3D -1; + + for (i =3D 0; i < caps->host.ncaches; i++) { + virCapsHostCacheBankPtr bank =3D caps->host.caches[i]; + if (VIR_ALLOC(node) < 0) + goto cleanup; + + if (virResctrlInfoGetMemory(caps->host.resctrl, bank->level, &node= ->control) > 0) { + node->id =3D bank->id; + if (!(node->cpus =3D virBitmapNewCopy(bank->cpus))) + goto cleanup; + + if (VIR_APPEND_ELEMENT(caps->host.nodes, + caps->host.nnodes, + node) < 0) { + goto cleanup; + } + } + virCapsHostMemoryNodeFree(node); + node =3D NULL; + } + + ret =3D 0; + cleanup: + virCapsHostMemoryNodeFree(node); + return ret; +} + + int virCapabilitiesInitCaches(virCapsPtr caps) { @@ -1731,6 +1836,9 @@ virCapabilitiesInitCaches(virCapsPtr caps) qsort(caps->host.caches, caps->host.ncaches, sizeof(*caps->host.caches), virCapsHostCacheBankSorter); =20 + if (virCapabilitiesInitResctrlMemory(caps) < 0) + goto cleanup; + ret =3D 0; cleanup: VIR_FREE(type); diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index fe1b9ea..73e165e 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -151,6 +151,14 @@ struct _virCapsHostCacheBank { virResctrlInfoPerCachePtr *controls; }; =20 +typedef struct _virCapsHostMemoryNode virCapsHostMemoryNode; +typedef virCapsHostMemoryNode *virCapsHostMemoryNodePtr; +struct _virCapsHostMemoryNode { + unsigned int id; + virBitmapPtr cpus; /* All CPUs that belong to this node*/ + virResctrlInfoPerNode control; +}; + typedef struct _virCapsHost virCapsHost; typedef virCapsHost *virCapsHostPtr; struct _virCapsHost { @@ -175,6 +183,9 @@ struct _virCapsHost { size_t ncaches; virCapsHostCacheBankPtr *caches; =20 + size_t nnodes; + virCapsHostMemoryNodePtr *nodes; + size_t nsecModels; virCapsHostSecModelPtr secModels; =20 diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index de736b0..17f0a58 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -611,6 +611,26 @@ virResctrlInfoIsEmpty(virResctrlInfoPtr resctrl) =20 =20 int +virResctrlInfoGetMemory(virResctrlInfoPtr resctrl, + unsigned int level, + virResctrlInfoPerNodePtr control) +{ + virResctrlInfoMBPtr mb_info =3D resctrl->mb_info; + + if (!mb_info) + return 0; + + if (mb_info->last_level_cache !=3D level) + return 0; + + control->granularity =3D mb_info->bandwidth_granularity; + control->min =3D mb_info->min_bandwidth; + control->max_allocation =3D mb_info->max_allocation; + return 1; +} + + +int virResctrlInfoGetCache(virResctrlInfoPtr resctrl, unsigned int level, unsigned long long size, diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index 5e78334..01fcade 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -50,6 +50,17 @@ struct _virResctrlInfoPerCache { unsigned int max_allocation; }; =20 +typedef struct _virResctrlInfoPerNode virResctrlInfoPerNode; +typedef virResctrlInfoPerNode *virResctrlInfoPerNodePtr; +struct _virResctrlInfoPerNode { + /* Smallest possible increase of the allocation bandwidth in percentag= e */ + unsigned int granularity; + /* Minimal allocatable bandwidth in percentage */ + unsigned int min; + /* Maximum number of simultaneous allocations */ + unsigned int max_allocation; +}; + typedef struct _virResctrlInfo virResctrlInfo; typedef virResctrlInfo *virResctrlInfoPtr; =20 @@ -63,6 +74,10 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, size_t *ncontrols, virResctrlInfoPerCachePtr **controls); =20 +int +virResctrlInfoGetMemory(virResctrlInfoPtr resctrl, + unsigned int level, + virResctrlInfoPerNodePtr control); /* Alloc-related things */ typedef struct _virResctrlAlloc virResctrlAlloc; typedef virResctrlAlloc *virResctrlAllocPtr; --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list