From nobody Fri May 3 18:01:14 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1502371920890141.35801882736484; Thu, 10 Aug 2017 06:32:00 -0700 (PDT) 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 CC4CE3E2C2; Thu, 10 Aug 2017 13:31:58 +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 28A7295684; Thu, 10 Aug 2017 13:31:58 +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 2C5094A468; Thu, 10 Aug 2017 13:31:56 +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 v7ADVt60022610 for ; Thu, 10 Aug 2017 09:31:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1C60697840; Thu, 10 Aug 2017 13:31:55 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DE0419783E for ; Thu, 10 Aug 2017 13:31:51 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.brq.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 2ED7B1203D5 for ; Thu, 10 Aug 2017 15:31:50 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CC4CE3E2C2 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 10 Aug 2017 15:31:45 +0200 Message-Id: <925c32e11c34213c685690a7df2a7c24d67a879b.1502368247.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/5] virxml: Fix indentation 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.30]); Thu, 10 Aug 2017 13:31:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Martin Kletzander --- src/util/virxml.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 666024809438..39049d869bc1 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -671,7 +671,7 @@ catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUS= ED, ...) return; =20 if (ctxt->_private) - domcode =3D ((struct virParserData *) ctxt->_private)->domcode; + domcode =3D ((struct virParserData *) ctxt->_private)->domcode; =20 =20 cur =3D ctxt->input->cur; @@ -718,7 +718,7 @@ catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUS= ED, ...) contextstr, pointerstr); } else { - virGenericReportError(domcode, VIR_ERR_XML_DETAIL, + virGenericReportError(domcode, VIR_ERR_XML_DETAIL, _("at line %d: %s%s\n%s"), ctxt->lastError.line, ctxt->lastError.message, @@ -928,26 +928,26 @@ char * virXMLNodeToString(xmlDocPtr doc, xmlNodePtr node) { - xmlBufferPtr xmlbuf =3D NULL; - char *ret =3D NULL; + xmlBufferPtr xmlbuf =3D NULL; + char *ret =3D NULL; =20 - if (!(xmlbuf =3D xmlBufferCreate())) { - virReportOOMError(); - return NULL; - } + if (!(xmlbuf =3D xmlBufferCreate())) { + virReportOOMError(); + return NULL; + } =20 - if (xmlNodeDump(xmlbuf, doc, node, 0, 1) =3D=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("failed to convert the XML node tree")); - goto cleanup; - } + if (xmlNodeDump(xmlbuf, doc, node, 0, 1) =3D=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("failed to convert the XML node tree")); + goto cleanup; + } =20 - ignore_value(VIR_STRDUP(ret, (const char *)xmlBufferContent(xmlbuf))); + ignore_value(VIR_STRDUP(ret, (const char *)xmlBufferContent(xmlbuf))); =20 cleanup: - xmlBufferFree(xmlbuf); + xmlBufferFree(xmlbuf); =20 - return ret; + return ret; } =20 typedef int (*virXMLForeachCallback)(xmlNodePtr node, @@ -1126,7 +1126,7 @@ virXMLNodeSanitizeNamespaces(xmlNodePtr node) xmlNodePtr dupl; =20 if (!node) - return; + return; =20 child =3D node->children; while (child) { --=20 2.14.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 18:01:14 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1502371938669995.8374642267144; Thu, 10 Aug 2017 06:32:18 -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 D5F38AF644; Thu, 10 Aug 2017 13:32:15 +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 ADFE8B1EDC; Thu, 10 Aug 2017 13:32:15 +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 5E1BB3FCFC; Thu, 10 Aug 2017 13:32:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7ADVt7v022617 for ; Thu, 10 Aug 2017 09:31:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 49AA978395; Thu, 10 Aug 2017 13:31:55 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1B12E7F3A0 for ; Thu, 10 Aug 2017 13:31:51 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.brq.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 3A45A1203D8 for ; Thu, 10 Aug 2017 15:31:50 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D5F38AF644 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 10 Aug 2017 15:31:46 +0200 Message-Id: <748b0d10911dcd7dc692f52fb72a56c53ec3a47e.1502368247.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] tests: Fix indentation in virfilewrapper.c 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.26]); Thu, 10 Aug 2017 13:32:17 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Martin Kletzander --- tests/virfilewrapper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/virfilewrapper.c b/tests/virfilewrapper.c index bf2fa6905a26..fede7b2e89a8 100644 --- a/tests/virfilewrapper.c +++ b/tests/virfilewrapper.c @@ -70,7 +70,7 @@ static void init_syms(void) =20 int virFileWrapperAddPrefix(const char *prefix, - const char *override) + const char *override) { /* Both parameters are mandatory */ if (!prefix || !override) @@ -145,7 +145,7 @@ virFileWrapperOverridePrefix(const char *path) do { \ init_syms(); \ \ - newpath =3D virFileWrapperOverridePrefix(path); \ + newpath =3D virFileWrapperOverridePrefix(path); \ if (!newpath) \ abort(); \ } while (0) --=20 2.14.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 18:01:14 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1502371938255677.8838432663754; Thu, 10 Aug 2017 06:32:18 -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 51C72C04A5A3; Thu, 10 Aug 2017 13:32:15 +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 2AEE9B1ED1; Thu, 10 Aug 2017 13:32:15 +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 CF6611805974; Thu, 10 Aug 2017 13:32:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7ADVt8d022605 for ; Thu, 10 Aug 2017 09:31:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0D3F793432; Thu, 10 Aug 2017 13:31:55 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8543C9568B for ; Thu, 10 Aug 2017 13:31:51 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.brq.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 4595A120463 for ; Thu, 10 Aug 2017 15:31:50 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 51C72C04A5A3 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 10 Aug 2017 15:31:47 +0200 Message-Id: <4f64b5cc2b5af3a96faf500f6c51d83b6d9da6e8.1502368247.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/5] Move resctrl-related code from conf/capabilities to util/virresctrl 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.32]); Thu, 10 Aug 2017 13:32:17 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It doesn't access anything from conf/ and ti will be needed to use from other util/ places. This split makes the separation clearer. Signed-off-by: Martin Kletzander --- include/libvirt/virterror.h | 1 + src/Makefile.am | 1 + src/conf/capabilities.c | 138 +++++---------------------------------- src/conf/capabilities.h | 26 +------- src/libvirt_private.syms | 7 ++ src/util/virerror.c | 1 + src/util/virresctrl.c | 153 ++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virresctrl.h | 63 ++++++++++++++++++ 8 files changed, 245 insertions(+), 145 deletions(-) create mode 100644 src/util/virresctrl.c create mode 100644 src/util/virresctrl.h diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 2efee8f0c086..3dd2d0822d6d 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -132,6 +132,7 @@ typedef enum { =20 VIR_FROM_PERF =3D 65, /* Error from perf */ VIR_FROM_LIBSSH =3D 66, /* Error from libssh connection transpor= t */ + VIR_FROM_RESCTRL =3D 67, /* Error from resource control */ =20 # ifdef VIR_ENUM_SENTINELS VIR_ERR_DOMAIN_LAST diff --git a/src/Makefile.am b/src/Makefile.am index b8e875482969..c3c7a8f04d36 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -167,6 +167,7 @@ UTIL_SOURCES =3D \ util/virprocess.c util/virprocess.h \ util/virqemu.c util/virqemu.h \ util/virrandom.h util/virrandom.c \ + util/virresctrl.h util/virresctrl.c \ util/virrotatingfile.h util/virrotatingfile.c \ util/virscsi.c util/virscsi.h \ util/virscsihost.c util/virscsihost.h \ diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index e851539bd677..18849adfcaec 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -31,8 +31,6 @@ #include =20 #include "capabilities.h" -#include "c-ctype.h" -#include "count-one-bits.h" #include "cpu_conf.h" #include "domain_conf.h" #include "physmem.h" @@ -52,7 +50,6 @@ #define VIR_FROM_THIS VIR_FROM_CAPABILITIES =20 #define SYSFS_SYSTEM_PATH "/sys/devices/system" -#define SYSFS_RESCTRL_PATH "/sys/fs/resctrl" =20 VIR_LOG_INIT("conf.capabilities") =20 @@ -1539,12 +1536,6 @@ VIR_ENUM_IMPL(virCacheKernel, VIR_CACHE_TYPE_LAST, "Instruction", "Data") =20 -/* Our naming for cache types and scopes */ -VIR_ENUM_IMPL(virCache, VIR_CACHE_TYPE_LAST, - "both", - "code", - "data") - bool virCapsHostCacheBankEquals(virCapsHostCacheBankPtr a, virCapsHostCacheBankPtr b) @@ -1571,111 +1562,6 @@ virCapsHostCacheBankFree(virCapsHostCacheBankPtr pt= r) VIR_FREE(ptr); } =20 -/* - * This function tests which TYPE of cache control is supported - * Return values are: - * -1: not supported - * 0: CAT - * 1: CDP - */ -static int -virCapabilitiesGetCacheControlType(virCapsHostCacheBankPtr bank) -{ - int ret =3D -1; - char *path =3D NULL; - - if (virAsprintf(&path, - SYSFS_RESCTRL_PATH "/info/L%u", - bank->level) < 0) - return -1; - - if (virFileExists(path)) { - ret =3D 0; - } else { - VIR_FREE(path); - /* - * If CDP is enabled, there will be both CODE and DATA, but it's e= nough - * to check one of those only. - */ - if (virAsprintf(&path, - SYSFS_RESCTRL_PATH "/info/L%uCODE", - bank->level) < 0) - return -1; - if (virFileExists(path)) - ret =3D 1; - } - - VIR_FREE(path); - return ret; -} - -static int -virCapabilitiesGetCacheControl(virCapsHostCacheBankPtr bank, - virCacheType scope) -{ - int ret =3D -1; - char *tmp =3D NULL; - char *path =3D NULL; - char *cbm_mask =3D NULL; - char *type_upper =3D NULL; - unsigned int bits =3D 0; - unsigned int min_cbm_bits =3D 0; - virCapsHostCacheControlPtr control; - - if (VIR_ALLOC(control) < 0) - goto cleanup; - - if (scope !=3D VIR_CACHE_TYPE_BOTH && - virStringToUpper(&type_upper, virCacheTypeToString(scope)) < 0) - goto cleanup; - - if (virFileReadValueUint(&control->max_allocation, - SYSFS_RESCTRL_PATH "/info/L%u%s/num_closids", - bank->level, - type_upper ? type_upper : "") < 0) - goto cleanup; - - if (virFileReadValueString(&cbm_mask, - SYSFS_RESCTRL_PATH - "/info/L%u%s/cbm_mask", - bank->level, - type_upper ? type_upper: "") < 0) - goto cleanup; - - if (virFileReadValueUint(&min_cbm_bits, - SYSFS_RESCTRL_PATH "/info/L%u%s/min_cbm_bits", - bank->level, - type_upper ? type_upper : "") < 0) - goto cleanup; - - virStringTrimOptionalNewline(cbm_mask); - - for (tmp =3D cbm_mask; *tmp !=3D '\0'; tmp++) { - if (c_isxdigit(*tmp)) - bits +=3D count_one_bits(virHexToBin(*tmp)); - } - - control->granularity =3D bank->size / bits; - if (min_cbm_bits !=3D 1) - control->min =3D min_cbm_bits * control->granularity; - - control->scope =3D scope; - - if (VIR_APPEND_ELEMENT(bank->controls, - bank->ncontrols, - control) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - VIR_FREE(path); - VIR_FREE(cbm_mask); - VIR_FREE(type_upper); - VIR_FREE(control); - return ret; -} - int virCapabilitiesInitCaches(virCapsPtr caps) { @@ -1760,17 +1646,27 @@ virCapabilitiesInitCaches(virCapsPtr caps) SYSFS_SYSTEM_PATH, pos, ent->d_name= ) < 0) goto cleanup; =20 - typeret =3D virCapabilitiesGetCacheControlType(bank); + typeret =3D virResctrlGetCacheControlType(bank->level); =20 if (typeret =3D=3D 0) { - if (virCapabilitiesGetCacheControl(bank, - VIR_CACHE_TYPE_BOTH) < = 0) + if (virResctrlGetCacheInfo(bank->level, + bank->size, + VIR_CACHE_TYPE_BOTH, + &bank->controls, + &bank->ncontrols) < 0) goto cleanup; } else if (typeret =3D=3D 1) { - if (virCapabilitiesGetCacheControl(bank, - VIR_CACHE_TYPE_CODE) < = 0 || - virCapabilitiesGetCacheControl(bank, - VIR_CACHE_TYPE_DATA) < = 0) + if (virResctrlGetCacheInfo(bank->level, + bank->size, + VIR_CACHE_TYPE_CODE, + &bank->controls, + &bank->ncontrols) < 0) + goto cleanup; + if (virResctrlGetCacheInfo(bank->level, + bank->size, + VIR_CACHE_TYPE_DATA, + &bank->controls, + &bank->ncontrols) < 0) goto cleanup; } =20 diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 39a9bc689279..bd64498d1c7c 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -30,6 +30,7 @@ # include "virarch.h" # include "virmacaddr.h" # include "virobject.h" +# include "virresctrl.h" =20 # include =20 @@ -138,29 +139,6 @@ struct _virCapsHostSecModel { virCapsHostSecModelLabelPtr labels; }; =20 -typedef enum { - VIR_CACHE_TYPE_BOTH, - VIR_CACHE_TYPE_CODE, - VIR_CACHE_TYPE_DATA, - - VIR_CACHE_TYPE_LAST -} virCacheType; - -VIR_ENUM_DECL(virCache); - -typedef struct _virCapsHostCacheControl virCapsHostCacheControl; -typedef virCapsHostCacheControl *virCapsHostCacheControlPtr; -struct _virCapsHostCacheControl { - /* Smallest possible increase of the allocation size in bytes */ - unsigned long long granularity; - /* Minimal allocatable size in bytes (if different from granularity) */ - unsigned long long min; - /* Type of the allocation */ - virCacheType scope; - /* Maximum number of simultaneous allocations */ - unsigned int max_allocation; -}; - typedef struct _virCapsHostCacheBank virCapsHostCacheBank; typedef virCapsHostCacheBank *virCapsHostCacheBankPtr; struct _virCapsHostCacheBank { @@ -170,7 +148,7 @@ struct _virCapsHostCacheBank { virCacheType type; /* Data, Instruction or Unified */ virBitmapPtr cpus; /* All CPUs that share this bank */ size_t ncontrols; - virCapsHostCacheControlPtr *controls; + virResctrlPtr *controls; }; =20 typedef struct _virCapsHost virCapsHost; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 183a9194d766..9de19628d480 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2464,6 +2464,13 @@ virRandomGenerateWWN; virRandomInt; =20 =20 +# util/virresctrl.h +virCacheTypeFromString; +virCacheTypeToString; +virResctrlGetCacheControlType; +virResctrlGetCacheInfo; + + # util/virrotatingfile.h virRotatingFileReaderConsume; virRotatingFileReaderFree; diff --git a/src/util/virerror.c b/src/util/virerror.c index ef17fb5e6e74..a5a2d6ed10f3 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -139,6 +139,7 @@ VIR_ENUM_IMPL(virErrorDomain, VIR_ERR_DOMAIN_LAST, =20 "Perf", /* 65 */ "Libssh transport layer", + "Resource control", ) =20 =20 diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c new file mode 100644 index 000000000000..dfc062c2a0f8 --- /dev/null +++ b/src/util/virresctrl.c @@ -0,0 +1,153 @@ +/* + * virresctrl.c: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "virresctrl.h" + +#include "c-ctype.h" +#include "count-one-bits.h" +#include "viralloc.h" +#include "virfile.h" +#include "virlog.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_RESCTRL + +VIR_LOG_INIT("util.virresctrl") + +#define SYSFS_RESCTRL_PATH "/sys/fs/resctrl" + +/* Resctrl is short for Resource Control. It might be implemented for var= ious + * resources, but at the time of this writing this is only supported for c= ache + * allocation technology (aka CAT). Hence the reson for leaving 'Cache' o= ut of + * all the structure and function names for now (can be added later if nee= ded. + */ + +/* Our naming for cache types and scopes */ +VIR_ENUM_IMPL(virCache, VIR_CACHE_TYPE_LAST, + "both", + "code", + "data") + +int +virResctrlGetCacheInfo(unsigned int level, + unsigned long long size, + virCacheType scope, + virResctrlPtr **controls, + size_t *ncontrols) +{ + int ret =3D -1; + char *tmp =3D NULL; + char *path =3D NULL; + char *cbm_mask =3D NULL; + char *type_upper =3D NULL; + unsigned int bits =3D 0; + unsigned int min_cbm_bits =3D 0; + virResctrlPtr control; + + if (VIR_ALLOC(control) < 0) + goto cleanup; + + if (scope !=3D VIR_CACHE_TYPE_BOTH && + virStringToUpper(&type_upper, virCacheTypeToString(scope)) < 0) + goto cleanup; + + if (virFileReadValueUint(&control->max_allocation, + SYSFS_RESCTRL_PATH "/info/L%u%s/num_closids", + level, + type_upper ? type_upper : "") < 0) + goto cleanup; + + if (virFileReadValueString(&cbm_mask, + SYSFS_RESCTRL_PATH + "/info/L%u%s/cbm_mask", + level, + type_upper ? type_upper: "") < 0) + goto cleanup; + + if (virFileReadValueUint(&min_cbm_bits, + SYSFS_RESCTRL_PATH "/info/L%u%s/min_cbm_bits", + level, + type_upper ? type_upper : "") < 0) + goto cleanup; + + virStringTrimOptionalNewline(cbm_mask); + + for (tmp =3D cbm_mask; *tmp !=3D '\0'; tmp++) { + if (c_isxdigit(*tmp)) + bits +=3D count_one_bits(virHexToBin(*tmp)); + } + + control->granularity =3D size / bits; + if (min_cbm_bits !=3D 1) + control->min =3D min_cbm_bits * control->granularity; + + control->scope =3D scope; + + if (VIR_APPEND_ELEMENT(*controls, *ncontrols, control) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + VIR_FREE(path); + VIR_FREE(cbm_mask); + VIR_FREE(type_upper); + VIR_FREE(control); + return ret; +} + + +/* + * This function tests which TYPE of cache control is supported + * Return values are: + * -1: not supported + * 0: CAT + * 1: CDP + */ +int +virResctrlGetCacheControlType(unsigned int level) +{ + int ret =3D -1; + char *path =3D NULL; + + if (virAsprintf(&path, + SYSFS_RESCTRL_PATH "/info/L%u", + level) < 0) + return -1; + + if (virFileExists(path)) { + ret =3D 0; + } else { + VIR_FREE(path); + /* + * If CDP is enabled, there will be both CODE and DATA, but it's e= nough + * to check one of those only. + */ + if (virAsprintf(&path, + SYSFS_RESCTRL_PATH "/info/L%uCODE", + level) < 0) + return -1; + if (virFileExists(path)) + ret =3D 1; + } + + VIR_FREE(path); + return ret; +} diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h new file mode 100644 index 000000000000..ee219cbb9261 --- /dev/null +++ b/src/util/virresctrl.h @@ -0,0 +1,63 @@ +/* + * virresctrl.h: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#ifndef __VIR_RESCTRL_H__ +# define __VIR_RESCTRL_H__ + +# include "internal.h" + +# include "virbitmap.h" +# include "virutil.h" + + +typedef enum { + VIR_CACHE_TYPE_BOTH, + VIR_CACHE_TYPE_CODE, + VIR_CACHE_TYPE_DATA, + + VIR_CACHE_TYPE_LAST +} virCacheType; + +VIR_ENUM_DECL(virCache); + + +typedef struct _virResctrl virResctrl; +typedef virResctrl *virResctrlPtr; +struct _virResctrl { + /* Smallest possible increase of the allocation size in bytes */ + unsigned long long granularity; + /* Minimal allocatable size in bytes (if different from granularity) */ + unsigned long long min; + /* Type of the allocation */ + virCacheType scope; + /* Maximum number of simultaneous allocations */ + unsigned int max_allocation; +}; + + +int +virResctrlGetCacheInfo(unsigned int level, + unsigned long long size, + virCacheType scope, + virResctrlPtr **controls, + size_t *ncontrols); + +int +virResctrlGetCacheControlType(unsigned int level); + +#endif /* __VIR_RESCTRL_H__ */ --=20 2.14.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 18:01:14 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1502371920803873.0670371103578; Thu, 10 Aug 2017 06:32:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CC1D9554C2; Thu, 10 Aug 2017 13:31:58 +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 2F26360BEB; Thu, 10 Aug 2017 13:31:58 +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 26CBF4BB79; Thu, 10 Aug 2017 13:31:55 +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 v7ADVsjL022591 for ; Thu, 10 Aug 2017 09:31:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6460FB1EDE; Thu, 10 Aug 2017 13:31:54 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0BBA1B1ED5 for ; Thu, 10 Aug 2017 13:31:51 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.brq.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 54DA51204A5 for ; Thu, 10 Aug 2017 15:31:50 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CC1D9554C2 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 10 Aug 2017 15:31:48 +0200 Message-Id: <15204a322ee1436887d84add58d7b5ee6589268e.1502368247.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/5] util: Make virResctrlGetCacheControlType() behave like other functions 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 10 Aug 2017 13:31:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" That means that returning negative values means error and non-negative values differ in meaning, but are all successful. Signed-off-by: Martin Kletzander --- src/conf/capabilities.c | 6 ++-- src/util/virresctrl.c | 84 ++++++++++++++++++++++++++++++++++-----------= ---- 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 18849adfcaec..69af3911a083 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1647,15 +1647,17 @@ virCapabilitiesInitCaches(virCapsPtr caps) goto cleanup; =20 typeret =3D virResctrlGetCacheControlType(bank->level); + if (typeret < 0) + goto cleanup; =20 - if (typeret =3D=3D 0) { + if (typeret =3D=3D 1) { if (virResctrlGetCacheInfo(bank->level, bank->size, VIR_CACHE_TYPE_BOTH, &bank->controls, &bank->ncontrols) < 0) goto cleanup; - } else if (typeret =3D=3D 1) { + } else if (typeret =3D=3D 2) { if (virResctrlGetCacheInfo(bank->level, bank->size, VIR_CACHE_TYPE_CODE, diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index dfc062c2a0f8..ec1ad7b6edad 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -45,6 +45,16 @@ VIR_ENUM_IMPL(virCache, VIR_CACHE_TYPE_LAST, "code", "data") =20 +/* + * This is the same enum, but for the resctrl naming + * of the type (L) + */ +VIR_ENUM_DECL(virResctrl) +VIR_ENUM_IMPL(virResctrl, VIR_CACHE_TYPE_LAST, + "", + "CODE", + "DATA") + int virResctrlGetCacheInfo(unsigned int level, unsigned long long size, @@ -114,40 +124,64 @@ virResctrlGetCacheInfo(unsigned int level, } =20 =20 +static inline int +virResctrlGetCacheDir(char **path, + const char *prefix, + unsigned int level, + virCacheType type) +{ + return virAsprintf(path, + SYSFS_RESCTRL_PATH "%s/L%u%s", + prefix ? prefix : "", + level, + virResctrlTypeToString(type)); +} + + +/* + * This function tests whether TYPE of cache control is supported or not. + * + * Returns 0 if not, 1 if yes and negative value on error. + */ +static int +virResctrlGetCacheSupport(unsigned int level, virCacheType type) +{ + int ret =3D -1; + char *path =3D NULL; + + if (virResctrlGetCacheDir(&path, "/info", level, type) < 0) + return -1; + + ret =3D virFileExists(path); + VIR_FREE(path); + return ret; +} + + /* * This function tests which TYPE of cache control is supported * Return values are: - * -1: not supported - * 0: CAT - * 1: CDP + * -1: error + * 0: none + * 1: CAT + * 2: CDP */ int virResctrlGetCacheControlType(unsigned int level) { - int ret =3D -1; - char *path =3D NULL; + int rv =3D -1; =20 - if (virAsprintf(&path, - SYSFS_RESCTRL_PATH "/info/L%u", - level) < 0) + rv =3D virResctrlGetCacheSupport(level, VIR_CACHE_TYPE_BOTH); + if (rv < 0) return -1; + if (rv) + return 1; =20 - if (virFileExists(path)) { - ret =3D 0; - } else { - VIR_FREE(path); - /* - * If CDP is enabled, there will be both CODE and DATA, but it's e= nough - * to check one of those only. - */ - if (virAsprintf(&path, - SYSFS_RESCTRL_PATH "/info/L%uCODE", - level) < 0) - return -1; - if (virFileExists(path)) - ret =3D 1; - } + rv =3D virResctrlGetCacheSupport(level, VIR_CACHE_TYPE_CODE); + if (rv < 0) + return -1; + if (rv) + return 2; =20 - VIR_FREE(path); - return ret; + return 0; } --=20 2.14.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Fri May 3 18:01:14 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1502371939442273.3995204672947; Thu, 10 Aug 2017 06:32:19 -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 E3EEB7EAA1; Thu, 10 Aug 2017 13:32:16 +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 8481EB1ECD; Thu, 10 Aug 2017 13:32:16 +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 1C8FA268; Thu, 10 Aug 2017 13:32:16 +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 v7ADVt4f022627 for ; Thu, 10 Aug 2017 09:31:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id D6EFC97840; Thu, 10 Aug 2017 13:31:55 +0000 (UTC) Received: from caroline.localdomain (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A8B2E9783B for ; Thu, 10 Aug 2017 13:31:55 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.brq.redhat.com [127.0.0.1]) by caroline.localdomain (Postfix) with ESMTP id 607FA1204E0 for ; Thu, 10 Aug 2017 15:31:50 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E3EEB7EAA1 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 10 Aug 2017 15:31:49 +0200 Message-Id: <679ad471aa9aedd287716cf326b588f904d237a5.1502368247.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/5] util: Rename virResctrl to virResctrlInfo 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.28]); Thu, 10 Aug 2017 13:32:18 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This way later patches can add another structures with virResctrl prefix without the meaning being even more confusing than it needs to be. Signed-off-by: Martin Kletzander --- src/conf/capabilities.h | 2 +- src/util/virresctrl.c | 4 ++-- src/util/virresctrl.h | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index bd64498d1c7c..5048fa819d95 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -148,7 +148,7 @@ struct _virCapsHostCacheBank { virCacheType type; /* Data, Instruction or Unified */ virBitmapPtr cpus; /* All CPUs that share this bank */ size_t ncontrols; - virResctrlPtr *controls; + virResctrlInfoPtr *controls; }; =20 typedef struct _virCapsHost virCapsHost; diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index ec1ad7b6edad..2a11825a52dc 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -59,7 +59,7 @@ int virResctrlGetCacheInfo(unsigned int level, unsigned long long size, virCacheType scope, - virResctrlPtr **controls, + virResctrlInfoPtr **controls, size_t *ncontrols) { int ret =3D -1; @@ -69,7 +69,7 @@ virResctrlGetCacheInfo(unsigned int level, char *type_upper =3D NULL; unsigned int bits =3D 0; unsigned int min_cbm_bits =3D 0; - virResctrlPtr control; + virResctrlInfoPtr control; =20 if (VIR_ALLOC(control) < 0) goto cleanup; diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h index ee219cbb9261..848b13e98aa3 100644 --- a/src/util/virresctrl.h +++ b/src/util/virresctrl.h @@ -36,9 +36,9 @@ typedef enum { VIR_ENUM_DECL(virCache); =20 =20 -typedef struct _virResctrl virResctrl; -typedef virResctrl *virResctrlPtr; -struct _virResctrl { +typedef struct _virResctrlInfo virResctrlInfo; +typedef virResctrlInfo *virResctrlInfoPtr; +struct _virResctrlInfo { /* Smallest possible increase of the allocation size in bytes */ unsigned long long granularity; /* Minimal allocatable size in bytes (if different from granularity) */ @@ -54,7 +54,7 @@ int virResctrlGetCacheInfo(unsigned int level, unsigned long long size, virCacheType scope, - virResctrlPtr **controls, + virResctrlInfoPtr **controls, size_t *ncontrols); =20 int --=20 2.14.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list