From nobody Wed May 14 03:48:54 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=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152837969271547.11562050053567; Thu, 7 Jun 2018 06:54:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD32E308A94C; Thu, 7 Jun 2018 13:54:51 +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 686B5617A5; Thu, 7 Jun 2018 13:54:51 +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 0EEB14CA87; Thu, 7 Jun 2018 13:54:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w57DsZHL000430 for ; Thu, 7 Jun 2018 09:54:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4573F202699A; Thu, 7 Jun 2018 13:54:35 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0767D2026DEF for ; Thu, 7 Jun 2018 13:54:35 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id 120C212006F for ; Thu, 7 Jun 2018 15:54:33 +0200 (CEST) From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 7 Jun 2018 15:54:27 +0200 Message-Id: <668abca3969e114aa64b88315b735da4f3c311c4.1528377367.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/10] util: Reorder parts of 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 07 Jun 2018 13:54:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move description of the purpose of the file before any definition. One empty line between related enum definitions. All typedefs before all structs. This is exception from the usual, but not= the only one, we already have something similar for some other structs. This w= ay we can move contents between structs and reorder some parts nicely without mov= ing all definitions of one type before another one just so it's defined. Define all classes in one place. Have one initialization function for all classes in the file. Signed-off-by: Martin Kletzander Reviewed-by: J=EF=BF=BDn Tomko --- src/util/virresctrl.c | 156 +++++++++++++++++++++--------------------- 1 file changed, 79 insertions(+), 77 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index ef649a08bf73..0266fee4e959 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -37,21 +37,22 @@ VIR_LOG_INIT("util.virresctrl") =20 =20 -/* Common definitions */ -#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. */ =20 + +/* Common definitions */ +#define SYSFS_RESCTRL_PATH "/sys/fs/resctrl" + + /* Our naming for cache types and scopes */ VIR_ENUM_IMPL(virCache, VIR_CACHE_TYPE_LAST, "both", "code", "data") - /* * This is the same enum, but for the resctrl naming * of the type (L) @@ -63,9 +64,28 @@ VIR_ENUM_IMPL(virResctrl, VIR_CACHE_TYPE_LAST, "DATA") =20 =20 -/* Info-related definitions and InfoClass-related functions */ +/* All private typedefs so that they exist for all later definitions. Thi= s way + * structs can be included in one or another without reorganizing the code= every + * time. */ typedef struct _virResctrlInfoPerType virResctrlInfoPerType; typedef virResctrlInfoPerType *virResctrlInfoPerTypePtr; + +typedef struct _virResctrlInfoPerLevel virResctrlInfoPerLevel; +typedef virResctrlInfoPerLevel *virResctrlInfoPerLevelPtr; + +typedef struct _virResctrlAllocPerType virResctrlAllocPerType; +typedef virResctrlAllocPerType *virResctrlAllocPerTypePtr; + +typedef struct _virResctrlAllocPerLevel virResctrlAllocPerLevel; +typedef virResctrlAllocPerLevel *virResctrlAllocPerLevelPtr; + + +/* Class definitions and initializations */ +static virClassPtr virResctrlInfoClass; +static virClassPtr virResctrlAllocClass; + + +/* virResctrlInfo */ struct _virResctrlInfoPerType { /* Kernel-provided information */ char *cbm_mask; @@ -86,8 +106,6 @@ struct _virResctrlInfoPerType { virResctrlInfoPerCache control; }; =20 -typedef struct _virResctrlInfoPerLevel virResctrlInfoPerLevel; -typedef virResctrlInfoPerLevel *virResctrlInfoPerLevelPtr; struct _virResctrlInfoPerLevel { virResctrlInfoPerTypePtr *types; }; @@ -99,7 +117,6 @@ struct _virResctrlInfo { size_t nlevels; }; =20 -static virClassPtr virResctrlInfoClass; =20 static void virResctrlInfoDispose(void *obj) @@ -130,30 +147,7 @@ virResctrlInfoDispose(void *obj) } =20 =20 -static int -virResctrlInfoOnceInit(void) -{ - if (!VIR_CLASS_NEW(virResctrlInfo, virClassForObject())) - return -1; - - return 0; -} - - -VIR_ONCE_GLOBAL_INIT(virResctrlInfo) - - -virResctrlInfoPtr -virResctrlInfoNew(void) -{ - if (virResctrlInfoInitialize() < 0) - return NULL; - - return virObjectNew(virResctrlInfoClass); -} - - -/* Alloc-related definitions and AllocClass-related functions */ +/* virResctrlAlloc */ =20 /* * virResctrlAlloc represents one allocation (in XML under cputune/cachetu= ne and @@ -186,8 +180,6 @@ virResctrlInfoNew(void) * virBitmaps named `masks` indexed the same way as `sizes`. The upper bo= unds * of the sparse arrays are stored in nmasks or nsizes, respectively. */ -typedef struct _virResctrlAllocPerType virResctrlAllocPerType; -typedef virResctrlAllocPerType *virResctrlAllocPerTypePtr; struct _virResctrlAllocPerType { /* There could be bool saying whether this is set or not, but since ev= erything * in virResctrlAlloc (and most of libvirt) goes with pointer arrays w= e would @@ -201,8 +193,6 @@ struct _virResctrlAllocPerType { size_t nmasks; }; =20 -typedef struct _virResctrlAllocPerLevel virResctrlAllocPerLevel; -typedef virResctrlAllocPerLevel *virResctrlAllocPerLevelPtr; struct _virResctrlAllocPerLevel { virResctrlAllocPerTypePtr *types; /* Indexed with enum virCacheType */ /* There is no `ntypes` member variable as it is always allocated for @@ -222,7 +212,6 @@ struct _virResctrlAlloc { char *path; }; =20 -static virClassPtr virResctrlAllocClass; =20 static void virResctrlAllocDispose(void *obj) @@ -265,27 +254,20 @@ virResctrlAllocDispose(void *obj) } =20 =20 +/* Global initialization for classes */ static int -virResctrlAllocOnceInit(void) +virResctrlOnceInit(void) { + if (!VIR_CLASS_NEW(virResctrlInfo, virClassForObject())) + return -1; + if (!VIR_CLASS_NEW(virResctrlAlloc, virClassForObject())) return -1; =20 return 0; } =20 - -VIR_ONCE_GLOBAL_INIT(virResctrlAlloc) - - -virResctrlAllocPtr -virResctrlAllocNew(void) -{ - if (virResctrlAllocInitialize() < 0) - return NULL; - - return virObjectNew(virResctrlAllocClass); -} +VIR_ONCE_GLOBAL_INIT(virResctrl) =20 =20 /* Common functions */ @@ -331,32 +313,7 @@ virResctrlUnlock(int fd) } =20 =20 -/* Info-related functions */ -static bool -virResctrlInfoIsEmpty(virResctrlInfoPtr resctrl) -{ - size_t i =3D 0; - size_t j =3D 0; - - if (!resctrl) - return true; - - for (i =3D 0; i < resctrl->nlevels; i++) { - virResctrlInfoPerLevelPtr i_level =3D resctrl->levels[i]; - - if (!i_level) - continue; - - for (j =3D 0; j < VIR_CACHE_TYPE_LAST; j++) { - if (i_level->types[j]) - return false; - } - } - - return true; -} - - +/* virResctrlInfo-related definitions */ int virResctrlGetInfo(virResctrlInfoPtr resctrl) { @@ -488,6 +445,41 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl) } =20 =20 +virResctrlInfoPtr +virResctrlInfoNew(void) +{ + if (virResctrlInitialize() < 0) + return NULL; + + return virObjectNew(virResctrlInfoClass); +} + + +static bool +virResctrlInfoIsEmpty(virResctrlInfoPtr resctrl) +{ + size_t i =3D 0; + size_t j =3D 0; + + if (!resctrl) + return true; + + for (i =3D 0; i < resctrl->nlevels; i++) { + virResctrlInfoPerLevelPtr i_level =3D resctrl->levels[i]; + + if (!i_level) + continue; + + for (j =3D 0; j < VIR_CACHE_TYPE_LAST; j++) { + if (i_level->types[j]) + return false; + } + } + + return true; +} + + int virResctrlInfoGetCache(virResctrlInfoPtr resctrl, unsigned int level, @@ -552,7 +544,17 @@ virResctrlInfoGetCache(virResctrlInfoPtr resctrl, } =20 =20 -/* Alloc-related functions */ +/* virResctrlAlloc-related definitions */ +virResctrlAllocPtr +virResctrlAllocNew(void) +{ + if (virResctrlInitialize() < 0) + return NULL; + + return virObjectNew(virResctrlAllocClass); +} + + bool virResctrlAllocIsEmpty(virResctrlAllocPtr alloc) { --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list