From nobody Mon Feb 9 09:22:57 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 153743831815712.424651595294677; Thu, 20 Sep 2018 03:11:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8DBCF3084033; Thu, 20 Sep 2018 10:11:55 +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 E134B85A38; Thu, 20 Sep 2018 10:11:54 +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 352F2181A130; Thu, 20 Sep 2018 10:11:53 +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 w8KABopk010624 for ; Thu, 20 Sep 2018 06:11:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8065470A18; Thu, 20 Sep 2018 10:11:50 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A553284EE; Thu, 20 Sep 2018 10:11:48 +0000 (UTC) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 65DF230001DE; Thu, 20 Sep 2018 10:11:47 +0000 (UTC) Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Sep 2018 03:11:47 -0700 Received: from david-unc.bj.intel.com ([10.238.145.63]) by orsmga007.jf.intel.com with ESMTP; 20 Sep 2018 03:11:45 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,397,1531810800"; d="scan'208";a="74535834" From: Wang Huaqiang To: jferlan@redhat.com, libvir-list@redhat.com Date: Thu, 20 Sep 2018 18:10:47 +0800 Message-Id: <1537438250-3966-2-git-send-email-huaqiang.wang@intel.com> In-Reply-To: <1537438250-3966-1-git-send-email-huaqiang.wang@intel.com> References: <1537438250-3966-1-git-send-email-huaqiang.wang@intel.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 214 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 20 Sep 2018 10:11:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 20 Sep 2018 10:11:47 +0000 (UTC) for IP:'192.55.52.115' DOMAIN:'mga14.intel.com' HELO:'mga14.intel.com' FROM:'huaqiang.wang@intel.com' RCPT:'' X-RedHat-Spam-Score: -5.001 (RCVD_IN_DNSWL_HI, SPF_PASS) 192.55.52.115 mga14.intel.com 192.55.52.115 mga14.intel.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 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, bing.niu@intel.com, jian-feng.ding@intel.com, rui.zang@intel.com Subject: [libvirt] [PATCHv3 1/4] util: Introduce monitor capability interface 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 20 Sep 2018 10:11:56 +0000 (UTC) X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch introduces the resource monitor and creates the interface for getting host capability of resource monitor from the system resource control file system. The resource monitor takes the role of RDT monitoring group and could be used to monitor the resource consumption information, such as the last level cache occupancy and the utilization of memory bandwidth. Signed-off-by: Wang Huaqiang Reviewed-by: John Ferlan --- src/util/virresctrl.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 126 insertions(+) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 4b5442f..d1bd88c 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -83,6 +83,9 @@ typedef virResctrlInfoPerLevel *virResctrlInfoPerLevelPtr; typedef struct _virResctrlInfoMemBW virResctrlInfoMemBW; typedef virResctrlInfoMemBW *virResctrlInfoMemBWPtr; =20 +typedef struct _virResctrlInfoMongrp virResctrlInfoMongrp; +typedef virResctrlInfoMongrp *virResctrlInfoMongrpPtr; + typedef struct _virResctrlAllocPerType virResctrlAllocPerType; typedef virResctrlAllocPerType *virResctrlAllocPerTypePtr; =20 @@ -139,6 +142,28 @@ struct _virResctrlInfoMemBW { unsigned int max_id; }; =20 +struct _virResctrlInfoMongrp { + /* Maximum number of simultaneous monitors */ + unsigned int max_monitor; + /* null-terminal string list for monitor features */ + char **features; + /* Number of monitor features */ + size_t nfeatures; + + /* Last level cache related information */ + + /* This adjustable value affects the final reuse of resources used by + * monitor. After the action of removing a monitor, the kernel may not + * release all hardware resources that monitor used immediately if the + * cache occupancy value associated with 'removed' monitor is above th= is + * threshold. Once the cache occupancy is below this threshold, the + * underlying hardware resource will be reclaimed and be put into the + * resource pool for next reusing.*/ + unsigned int cache_reuse_threshold; + /* The cache 'level' that has the monitor capability */ + unsigned int cache_level; +}; + struct _virResctrlInfo { virObject parent; =20 @@ -146,6 +171,8 @@ struct _virResctrlInfo { size_t nlevels; =20 virResctrlInfoMemBWPtr membw_info; + + virResctrlInfoMongrpPtr monitor_info; }; =20 =20 @@ -171,8 +198,12 @@ virResctrlInfoDispose(void *obj) VIR_FREE(level); } =20 + if (resctrl->monitor_info) + virStringListFree(resctrl->monitor_info->features); + VIR_FREE(resctrl->membw_info); VIR_FREE(resctrl->levels); + VIR_FREE(resctrl->monitor_info); } =20 =20 @@ -555,6 +586,94 @@ virResctrlGetMemoryBandwidthInfo(virResctrlInfoPtr res= ctrl) } =20 =20 +/* + * Retrieve monitor capability from the resource control file system. + * + * The monitor capability is exposed through "SYSFS_RESCTRL_PATH/info/L3_M= ON" + * directory under the resource control file system. The monitor capabilit= y is + * parsed by reading the interface files and stored in the structure + * 'virResctrlInfoMongrp'. + * + * Not all host supports the resource monitor, leave the pointer + * @resctrl->monitor_info empty if not supported. + */ +static int +virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl) +{ + int ret =3D -1; + int rv =3D -1; + char *featurestr =3D NULL; + char **features =3D NULL; + size_t nfeatures =3D 0; + virResctrlInfoMongrpPtr info_monitor =3D NULL; + + if (VIR_ALLOC(info_monitor) < 0) + return -1; + + /* For now, monitor only exists in level 3 cache */ + info_monitor->cache_level =3D 3; + + rv =3D virFileReadValueUint(&info_monitor->max_monitor, + SYSFS_RESCTRL_PATH "/info/L3_MON/num_rmids"); + if (rv =3D=3D -2) { + /* The file doesn't exist, so it's unusable for us, probably resou= rce + * monitor unsupported */ + VIR_INFO("The path '" SYSFS_RESCTRL_PATH "/info/L3_MON/num_rmids' " + "does not exist"); + ret =3D 0; + virResetLastError(); + goto cleanup; + } else if (rv < 0) { + /* Other failures are fatal, so just quit */ + goto cleanup; + } + + rv =3D virFileReadValueUint(&info_monitor->cache_reuse_threshold, + SYSFS_RESCTRL_PATH + "/info/L3_MON/max_threshold_occupancy"); + if (rv =3D=3D -2) { + /* If CMT is not supported, then 'max_threshold_occupancy' file + * will not exist. */ + VIR_INFO("File '" SYSFS_RESCTRL_PATH + "/info/L3_MON/max_threshold_occupancy' does not exist"); + } else if (rv < 0) { + goto cleanup; + } + + rv =3D virFileReadValueString(&featurestr, + SYSFS_RESCTRL_PATH + "/info/L3_MON/mon_features"); + if (rv =3D=3D -2) + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Cannot get mon_features from resctrl")); + if (rv < 0) + goto cleanup; + + if (!*featurestr) { + /* If no feature found in "/info/L3_MON/mon_features", + * some error happens */ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Get empty feature list from resctrl")); + ret =3D -1; + goto cleanup; + } + + features =3D virStringSplitCount(featurestr, "\n", 0, &nfeatures); + VIR_DEBUG("Resctrl supported %ld monitoring features", nfeatures); + + info_monitor->nfeatures =3D nfeatures; + VIR_STEAL_PTR(info_monitor->features, features); + VIR_STEAL_PTR(resctrl->monitor_info, info_monitor); + + ret =3D 0; + cleanup: + VIR_FREE(featurestr); + virStringListFree(features); + VIR_FREE(info_monitor); + return ret; +} + + static int virResctrlGetInfo(virResctrlInfoPtr resctrl) { @@ -573,6 +692,10 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) if (ret < 0) goto cleanup; =20 + ret =3D virResctrlGetMonitorInfo(resctrl); + if (ret < 0) + goto cleanup; + ret =3D 0; cleanup: VIR_DIR_CLOSE(dirp); @@ -613,6 +736,9 @@ virResctrlInfoIsEmpty(virResctrlInfoPtr resctrl) if (resctrl->membw_info) return false; =20 + if (resctrl->monitor_info) + return false; + for (i =3D 0; i < resctrl->nlevels; i++) { virResctrlInfoPerLevelPtr i_level =3D resctrl->levels[i]; =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list